Harish
Harish

Reputation: 341

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

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

Answers (6)

RemcoW
RemcoW

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

Furqan Ud Din
Furqan Ud Din

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

Sonali Das
Sonali Das

Reputation: 1026

driver.findelement(By.(locator(locator details)).sendKeys(Keys.ARROW-DOWN,Keys.RETURN)

Upvotes: 0

KanikaGoyal
KanikaGoyal

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

ibaralf
ibaralf

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

Purendra Agrawal
Purendra Agrawal

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

Related Questions