Reputation: 1
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
Reputation: 8322
There might be two problems with your example:
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
the last forEach
loop should look like this:
clickableElements.forEach(element => {
console.log(elemtent.getText() + "is clickable");
});
Upvotes: 0