1

How to check if an element is truly clickable in selenium webdriverJS?

I know that I can check if element is displayed and if element is enabled. However, if the element is hidden by some other element, say for example, by a modal popup, it can't be clicked. In that case, I want webdriver to wait until the element is truly clickable.

How to do this? Thanks for the help

1 Answer 1

1

I was facing this problem and final found a solution. Even tho I'm using wd instead of selenium-webdriver, I think my solution might be useful for who ever is working on selenium with Node.js.

Basically, I use the generic waitFor together with an asserter to keep trying the click until it success or timeout. And here is the code

usage

browser
    .elementById('some-button')
    .clickWhenClickable()

methods.js

var wd = require('wd');
var asserters = require('./asserters');
wd.addElementPromiseMethod('clickWhenClickable', function clickWhenClickable (timeout, pollFreq) {
  return this.browser.waitFor(asserters.elementHasBeenClicked(this), timeout, pollFreq);
});

asserters.js

var wd = require('wd');
var Asserter = wd.Asserter;

exports.elementHasBeenClicked = function elementHasBeenClicked (el) {
  return new Asserter(function hasBeenClicked (browser, cb) {
    el.click(function(err) {
      cb(null, !err, null);
    });
  });
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.