13

How can I simulate the ENTER key press using selenium python bindings? I have tried the following block but it is not working.

driver.find_element_by_xpath("html/xxxxx").send_keys('keys.ENTER')

or

driver.find_element_by_name("element_name").send_keys("ENTER")
Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
user1537127
  • 187
  • 2
  • 2
  • 6
  • Actually, even though it the same question in essence, the problem here is that very often a webpage will not accept `.send_keys(ENTER)` or anything like that, and instead the unicodes have to be used. Please do not remove this question from SO, as the other question does not mention the unicodes at all. – Alichino Jul 22 '16 at 09:27

2 Answers2

32

Use these codes from the API docs: http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.common.keys

Eg. ENTER would be .send_keys(u'\ue007')

Alichino
  • 1,668
  • 2
  • 16
  • 25
1

Try keys.ENTER, not as a string (take the single quotes off).

Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
drez90
  • 814
  • 5
  • 17
  • Hi,Thank you for this answer. Actually the webpage donot accept any keyboard inputs, other than ARROW KEYS and ENTER button. control is not navigating to the particular button on which i want to press ENTER. I am using this block of code..... driver.find_element_by_name("element_name").send_keys('ArrowLeft') driver.find_element_by_name("element_name").send_keys('ENTER') it fails every time. – user1537127 Jul 13 '16 at 11:02