19
votes

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 Arrow key followed by "Enter" key?

7
Can you post any code you have tried? - Aminah Nuraini

7 Answers

36
votes

You can import Keys and use these.

import org.openqa.selenium.Keys

WebElement.sendKeys(Keys.DOWN);
WebElement.sendKeys(Keys.RETURN);

Edit

You could probably use one sendKeys() call:

WebElement.sendKeys(Keys.DOWN, Keys.RETURN);
2
votes

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

1
votes
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
votes
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
votes
driver.findelement(By.(locator(locator details)).sendKeys(Keys.ARROW-DOWN,Keys.RETURN)
0
votes

I have tried this and it worked for me.

WebElement dp_down = driver.findElement(By.xpath("enter-your-element-xpath-here");
dp_down.sendKeys(Keys.ARROW_DOWN, Keys.RETURN);

This is working fine for me without any issues. CHEERS!!!

-1
votes

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

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