0

I am new to webdriver io and I want to get all clickable elements using webdriver io and iterate through them. I came across 'browser.findElements' API, but could not get it to work. Can anyone provide me a sample code ?

var assert = require('assert');
var homePage = require("../../pages/home_page");

describe('Keyboard friendly home page', () => {  
  it('User should be able to navigate using tab',() => {
    browser.url(homePage.url);
    elements = browser.findElements("div");
    clickableElements = [];
    elements.forEach(element => {
      if (element.isDiplayed() && element.isClickable()) {
        clickableElements.push(element);
      }
    });

    
    clickableElements.array.forEach(element => {
      console.log(elemtent.getText() + "is clickable");
    });
  });
}); 
1
  • What is the error? Commented Nov 18, 2020 at 15:34

1 Answer 1

0

There might be two problems with your example:

  1. incorrect use of findElements, see documentation; you can use $$ command where you pass only a selector, no need to pass a location strategy as well

  2. the last forEach loop should look like this:

clickableElements.forEach(element => {
    console.log(elemtent.getText() + "is clickable");
});
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.