Search code examples
pythonseleniumfirefoxselenium-webdriverkeypress

Enter key press is not working in Firefox


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)

Solution

  • 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.