selenium-webdriverchimp.js

webdriver.io selecting multiple elements and clicking one by one


I'm using webdriver.io for some automated unit testing, I can select multiple elements using browser.elements

but I need to be able to click each of the selected elements

I know there's a browser.click() - but that would only click the first element I've been playing with this for last 3 hours - the documentation is kind of confusing on webdriver.io about using browser.elements

How do I trigger each of the selected element's click?

var selector = '.main-section * .tbody .td:nth-child(14) a';
// this gets an awway of element id's   
var selectedButtons = browser.elements(selector);

// log returned array
console.log(selectedButtons.value);
// this prints the elementId's
console.log(selectedButtons.value[1].element().value.ELEMENT);

Output:

 [ { ELEMENT: '0.23250146411810424-135',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-135' },
    index: 0 },
  { ELEMENT: '0.23250146411810424-136',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-136' },
    index: 1 },
  { ELEMENT: '0.23250146411810424-137',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-137' },
    index: 2 },
  { ELEMENT: '0.23250146411810424-138',
    selector: '.main-section * .tbody .td:nth-child(14) a',
    value: { ELEMENT: '0.23250146411810424-138' },
    index: 3 } ]

0.23250146411810424-136

using webdriver.io within chimp


Solution

  • The latest version of webdriver-sync added the functionality so that the returned elements have the webdriver.io prototype on them - that is that you can just call .click on the returned elements in the array.

    Version 0.45.x+ of chimp uses the latest webdriver-sync