21

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?

Ripon Al Wasim
  • 36,924
  • 42
  • 155
  • 176
Harish
  • 331
  • 1
  • 2
  • 3

6 Answers6

41

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);
Captain Jack Sparrow
  • 971
  • 1
  • 11
  • 28
RemcoW
  • 4,196
  • 1
  • 22
  • 37
2

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

ibaralf
  • 12,218
  • 5
  • 47
  • 69
0
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.

Laurenz Albe
  • 209,280
  • 17
  • 206
  • 263
  • Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Adriaan Oct 20 '22 at 14:41
0
driver.findelement(By.(locator(locator details)).sendKeys(Keys.ARROW-DOWN,Keys.RETURN)
Sonali Das
  • 943
  • 1
  • 7
  • 24
  • Please read [answer] and [edit] your answer to contain an explanation as to why this code would actually solve the problem at hand. Always remember that you're not only solving the problem, but are also educating the OP and any future readers of this post. – Adriaan Oct 20 '22 at 14:41
0

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!!!

Slava Rozhnev
  • 9,510
  • 6
  • 23
  • 39
-1

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

import org.openqa.selenium.Keys
WebElement.sendKeys(Keys.DOWN + Keys.ENTER);
Purendra Agrawal
  • 558
  • 1
  • 6
  • 17