Press TAB and then ENTER key in Selenium WebDriver with Ruby
Asked Answered
B

4

9

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

Beggary answered 6/4, 2012 at 8:24 Comment(0)
W
7

In Ruby user1316's code looks like

driver.action.send_keys(elementVisible, :tab).send_keys(elementVisible, :return).perform
Why answered 12/4, 2012 at 5:16 Comment(0)
S
3

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();

Sev answered 6/4, 2012 at 9:3 Comment(1)
it doesnot help. My case is that i cannot get the button element. But i still need to click the button. Is there any other better way to achieve this? thank youBeggary
V
1

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

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

Vanatta answered 27/6, 2021 at 2:12 Comment(0)
F
0

send ENTER in ruby:

@browser.action.send_keys("\n").perform
Foliated answered 23/11, 2015 at 4:9 Comment(1)
I think this doesn't work for me, like if I try going to google and typing asdf, then doing ENTER manually it works. Whereas if I use irb and programmatically start google and programmatically enter in asdf or manually type asdf. Then programmatically send ENTER, it doesn't work, whereas a manual enter doesDamascus

© 2022 - 2024 — McMap. All rights reserved.