How to press Down Arrow key followed by “Enter” button in Selenium WebDriver?

后端 未结 6 848
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 05:56

I am using Selenium Java. I need to enter value into text box and press down arrow to select suggestions and then press Enter key.

So, my question is how to press Down A

相关标签:
6条回答
  • 2021-02-19 06:20
    driver.findelement(By.(locator(locator details)).sendKeys(Keys.ARROW-DOWN,Keys.RETURN)
    
    0 讨论(0)
  • 2021-02-19 06:25

    You can import Keys and use these.

    import org.openqa.selenium.Keys
    
    WebElement.sendKeys(Keys.DOWN);
    WebElement.sendKeys(Keys.RETURN);
    

    Edit

    Could probably also be used in one sendKeys() call

    WebElement.sendKeys(Keys.DOWN, Keys.RETURN);
    
    0 讨论(0)
  • 2021-02-19 06:29
    using Keys = OpenQA.Selenium.Keys;
    
    //moves down arrow key from keyboard to the list of dropdown
    IWebElement.SendKeys(Keys.Down);
    //Hits Enter on the selected list from the dropdown
    IWebElement.SendKeys(Keys.Return);
    

    This will work.

    0 讨论(0)
  • 2021-02-19 06:32

    Even you can concatenate both the Down and Enter in a single statement.

    import org.openqa.selenium.Keys
    WebElement.sendKeys(Keys.DOWN + Keys.ENTER);
    
    0 讨论(0)
  • 2021-02-19 06:34
    input_element = @driver.find_element(:id,'input_id')
    input_element.send_keys(:arrow_down)
    

    A list of special character keys can be found here

    0 讨论(0)
  • 2021-02-19 06:37

    For Ruby, this would be:

    input_element = @driver.find_element(:id,'input_id')
    input_element.send_keys(:arrow_down)
    

    A list of special character keys can be found here

    0 讨论(0)
提交回复
热议问题