k rahul
k rahul

Reputation: 1

Find all clickable elements using webdriverio

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");
    });
  });
}); 

Upvotes: 0

Views: 1172

Answers (1)

pavelsaman
pavelsaman

Reputation: 8322

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");
});

Upvotes: 0

Related Questions