Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Press TAB and then ENTER key in Selenium WebDriver with Ruby

I am doing automated testing using Selenium WebDriver with Ruby. I need to click a button. I cannot get the button element by id or css or xpath as the button is transparent. I would like to use Tab and Enter key to press the button.

I can use Tab key to get the button as below:

@element.send_keys :tab
@element --> any javascript element visible in the browser

But how do I use the Enter key on the button?

Basically I need to achieve press Tab key and then press Enter key to click the button.

I am using Selenium WebDriver @driver = Selenium::WebDriver.for :firefox

like image 709
AJJ Avatar asked Apr 06 '12 08:04

AJJ


3 Answers

In Ruby user1316's code looks like

driver.action.send_keys(elementVisible, :tab).send_keys(elementVisible, :return).perform
like image 131
ShockwaveNN Avatar answered Oct 16 '22 08:10

ShockwaveNN


Keeping in mind the excerpt :

I can use tab key to get the button as

@element.send_keys :tab

@element --> any javascript element visible in the browser

but how do i use the enter key on the button??

In order to use the enter key on the button, you could try one of the solution provided using Ruby here. This basically talks about sending the :return value and not the :enter value i.e @element.send_keys :return and some additional information.

UPDATED:

I could provide some code in Java which tries to implement the problem conceptually using the info provided here. You could try to translate for the corresponding Ruby Selenium API.

The Code:

Actions builder = new Actions(driver);

builder.sendKeys( elementVisible, Keys.TAB).sendKeys(Keys.RETURN);

Action submitTheTransperentButton = builder.build();

submitTheTransperentButton.perform();

like image 3
self-babush Avatar answered Oct 16 '22 07:10

self-babush


use Selenium::WebDriver::Keys::KEYS[:tab]

ref: https://www.rubydoc.info/gems/selenium-webdriver/Selenium/WebDriver/Keys

like image 1
Armando Avatar answered Oct 16 '22 08:10

Armando