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

barlop
  • 12,887
  • 8
  • 80
  • 109
AJJ
  • 3,570
  • 7
  • 43
  • 76

4 Answers4

7

In Ruby user1316's code looks like

driver.action.send_keys(elementVisible, :tab).send_keys(elementVisible, :return).perform
ShockwaveNN
  • 2,227
  • 2
  • 29
  • 56
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();

Community
  • 1
  • 1
self-babush
  • 585
  • 3
  • 13
  • 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 you – AJJ Apr 06 '12 at 09:27
1

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

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

Armando
  • 603
  • 1
  • 5
  • 14
0

send ENTER in ruby:

@browser.action.send_keys("\n").perform
AlekseiPetrovski
  • 1,016
  • 9
  • 17
  • 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 does – barlop Dec 29 '18 at 05:02