Can't iterate through multiple selector ($$, findElements) webdriver.io

301 views Asked by At

I'm trying to use webdriver.io (https://webdriver.io/) with spectron for an electron application.

I'm able to access functions that findElement or $ contain. For example, I can use the .click() on this findElement ($) selector.

app.client.$('//button[@data-value, "Agree")]').click()

My application contains 4 buttons that have a data-value prop of Agree. This $ selector will just click on the first one. My goal is to iterate through alll of the "Agree" buttons and click on all of them.

I'm trying to do this:

app.client.$$('//button[@data-value, "Agree")]').forEach(button => button.click())

However, that's saying the forEach function doesn't exist as if app.client.$$ doesn't return an array, contrary to what this documentation says: https://webdriver.io/docs/api/browser/$$.html

If I try to resolve the promise returned by $$, by doing:

app.client.$$('//button[@data-value, "Agree")]').then(buttons => console.log(buttons))

I get an array of the 4 buttons, but only the ELEMENT identifier, index and element object id appear. They do not include an extended prototype to run commands like .click() on them. I also cannot find any way to query for a particular ELEMENT ID using webdriver.

1

There are 1 answers

4
Mike G. On

Please upgrade from v4 to v5 or ideally to v6.

Cheers!