Reputation: 341
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?
Upvotes: 22
Views: 151436
Reputation: 4326
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);
Upvotes: 42
Reputation: 1
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!!!
Upvotes: 0
Reputation: 1026
driver.findelement(By.(locator(locator details)).sendKeys(Keys.ARROW-DOWN,Keys.RETURN)
Upvotes: 0
Reputation: 1
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.
Upvotes: 0
Reputation: 12518
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
Upvotes: 2
Reputation: 558
Even you can concatenate both the Down and Enter in a single statement.
import org.openqa.selenium.Keys
WebElement.sendKeys(Keys.DOWN + Keys.ENTER);
Upvotes: -1