I am using WebDriverIO to try to access (ie. getText, getAttribute, click, etc) an element after creating a list of elements. I am easily able to implement this element if I am using the browser.element()
method, but the moment I use browser.elements()
, I cannot access the individual objects in the array. According to the WebDriverIO docs, I should be able to access them using the value
property.
Here is my pseudo-code. I assumed that these two functions should return the same thing:
usingElement() {
return browser.element('.someCss');
}
usingElements() {
return browser.elements('.someCss').value[0];
}
When I try to use the first block of code, it works perfectly fine.. but
when I try to use the second block, it gives me an error saying usingElements.click is not a function
or usingElements.getText is not a function
, etc.
How can I isolate a single element object after using the browser.elements() method?
Your index reference was placed in the wrong spot. Try:
You don't need to reference the
value
property, as WebdriverIO is smart enough to infer that for you.I guess you might need to use one of the below two ways:
Way 1:
Way 2:
Thanks, Naveen