X
X
xxx2017-02-11 20:25:59
Python
xxx, 2017-02-11 20:25:59

Trouble passing Python variable?

I wrote an authorization script "VKontakte" and I want to send a message through the terminal as an input.

from selenium import webdriver
from time import sleep
from selenium.webdriver.common.keys import Keys
login = 
password = ""
message = str(input('Enter: '))
class Bot:
  def __init__(self):
    self.driver = webdriver.Firefox()
    self.navigate()

  def navigate(self):
    self.driver.get("https://vk.com/")
    field_number = self.driver.find_element_by_xpath('//input[@id="index_email"]')
   	field_number.send_keys(login)
   	field_password = self.driver.find_element_by_xpath('//input[@id="index_pass"]')
   	field_password.send_keys(password)
   	button = self.driver.find_element_by_xpath('//button[@id="index_login_button"]')
   	button.click()
   	sleep(1.5)
   	self.driver.get("https://vk.com/im")
   	a_message = self.driver.find_element_by_xpath('//li[@class="nim-dialog _im_dialog _im_dialog_22581127 nim-dialog_unread   nim-dialog_classic"]')
   	a_message.click()
   	sleep(1.5)
   	send_message = self.driver.find_element_by_xpath('//div[@id="im_editable0"]')
   	send_message.send_keys(message)
    send_message.send_keys(Keys.RETURN)

def main():
  b = Bot()

if __name__=="__main__":
  main()

Gives an error message:
Enter: Hello
Traceback (most recent call last):
  File "vk.py", line 6, in <module>
    message = str(input('Enter: '))
  File "<string>", line 1, in <module>
NameError: name 'Hello' is not defined

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Mindlin, 2017-02-11
@Heavy10110

Try
replacing with
raw_input('')

S
sim3x, 2017-02-11
@sim3x

x = 
y = ""

+ fix indents

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question