Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 235
Harish Avatar asked Jun 15 '16 09:06

Harish


Video Answer


3 Answers

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);
like image 99
RemcoW Avatar answered Oct 11 '22 06:10

RemcoW


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

like image 21
ibaralf Avatar answered Oct 11 '22 05:10

ibaralf


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

A list of special character keys can be found here

like image 1
Avinash Saxean Avatar answered Oct 11 '22 05:10

Avinash Saxean