qaNoob
qaNoob

Reputation: 17

WebDriverIO select using elements index

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?

Upvotes: 0

Views: 7142

Answers (2)

Naveen Thiyagarajan
Naveen Thiyagarajan

Reputation: 588

I guess you might need to use one of the below two ways:

Way 1:

var elmnts = browser.elements('.someCss');
var element = elmnts.value[0].ELEMENT;
browser.elementIdClick(element);

Way 2:

var element = $$('.someCss')[0];
element.click();

Thanks, Naveen

Upvotes: 3

Kevin Lamping
Kevin Lamping

Reputation: 2269

Your index reference was placed in the wrong spot. Try:

var myElement = browser.elements('.someCss')[0];
myElement.click();

You don't need to reference the value property, as WebdriverIO is smart enough to infer that for you.

Upvotes: 0

Related Questions