0

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.