Press TAB and then press ENTER in Selenium WebDriver with Ruby

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

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

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

But how can I use the Enter key on a button?

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

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

Please help me. Thanks in advance.

+6
source share
3 answers

In Ruby user1316, the code looks like

driver.action.send_keys(elementVisible, :tab).send_keys(elementVisible, :return).perform 
+5
source

Bearing in mind the excerpt:

I can use the tab key to get the button

@ element.send_keys: tab

@element -> any javascript element visible in the browser

but how can I use the enter key on the button

To use the enter key on the button, you can try one of the solutions provided with Ruby here . This basically means sending a value :return , not a value :enter ie @element.send_keys :return and some additional information.

UPDATED:

I could provide some Java code that is trying to implement the problem conceptually using the information provided here . You can try translating the appropriate Ruby Selenium API.

The code:

Actions builder = new actions (driver);

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

Action submitTheTransperentButton = builder.build ();

submitTheTransperentButton.perform ();

+2
source

send ENTER to ruby:

 @browser.action.send_keys("\n").perform 
0
source

Source: https://habr.com/ru/post/912575/


All Articles