1

I'm trying to enter text into an input field using selenium but it's giving an error. The code is:

input1 = browser.find_element_by_xpath('//*[@id="login-dialog dialog"]/div[2]/div[2]/div[2]/form/div[1]/input')
input1.sendKeys("myusername")

However it gives this error

Traceback (most recent call last):
File "C:\Users\Bradley Jo\Desktop\Project\app.py", line 14, in 
<module>
input1.sendKeys("hello")
AttributeError: 'WebElement' object has no attribute 'sendKeys'
Joe Sgg
  • 71
  • 3
  • 8

2 Answers2

6

the method is not sendKeys. It is send_keys.

input1 = browser.find_element_by_xpath('//*[@id="login-dialog dialog"]/div[2]/div[2]/div[2]/form/div[1]/input')
input1.send_keys("myusername")
Murthi
  • 5,299
  • 1
  • 10
  • 15
0

You have to use actions instead of direct typing in input field. Please use the below portion of code

input1 = browser.find_element_by_xpath('//*[@id="login-dialog dialog"]/div[2]/div[2]/div[2]/form/div[1]/input')

actions = ActionChains(driver)
actions.move_to_element(input1).send_keys("myusername").perform()

If the browser is your driver then change driver with browser.

Mahmud Riad
  • 1,169
  • 1
  • 8
  • 19