1

I have a scenario which involves pressing Enter key in the webpage. For Chrome my code works fine but when it comes to Firefox my code is not working. Please help me with an idea so that I can automate Enter key press in Selenium Python for Firefox driver.

Below are the codes that I have used.

browser1.find_element_by_xpath("path").send_keys(u'\ue007')
browser1.find_element_by_xpath("path").send_keys(Keys.ENTER)
Andersson
  • 51,635
  • 17
  • 77
  • 129
Bhuvaneshwari K
  • 147
  • 1
  • 15

1 Answers1

0

Try

from selenium.webdriver.common.keys import Keys
driver.find_element_by_name("Value").send_keys(Keys.RETURN)

Note that RETURN = '\ue006'

EDIT

Keep Explicit and Implicit Waits always in mind when programming WebDriver. Be mindful of the Programming Language Preference button near the top.

EDIT

Try

WebElement anElement = driver.find_element_by_name("Value")
anElement.send_keys(Keys.RETURN)

If you have changed the selection criteria to wait for the element to be enabled then keep that change. When Selenium is having timing issues I find that separating the action from the find often helps.

MikeJRamsey56
  • 2,779
  • 1
  • 20
  • 34
  • Post your code and the console log showing the error. – MikeJRamsey56 Nov 21 '16 at 20:52
  • Hi, I have called the enter key press code twice. Its working now. Thanks browser1.find_element_by_xpath("path").send_keys(Keys.ENTER) calling the above line twice works fine. – Bhuvaneshwari K Jun 02 '17 at 11:40
  • @BhuvaneshwariKumarRaja It is likely that on the first pass the WebElement returned by the find_element_by_name is not ready to receive the input. You should fix this. One way is to add criteria to wait for the WebElement to be enabled. See [this](https://stackoverflow.com/questions/9161773/how-can-i-get-selenium-web-driver-to-wait-for-an-element-to-be-accessible-not-j) SO Q&A. – MikeJRamsey56 Jun 02 '17 at 14:02
  • I have even added webdriver wait, even then if i use enter key press two times only it is working. – Bhuvaneshwari K Jun 08 '17 at 12:35