WebDriverIO select using elements index

╄→尐↘猪︶ㄣ 提交于 2019-12-24 19:56:17

问题


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?


回答1:


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




回答2:


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.



来源:https://stackoverflow.com/questions/51255595/webdriverio-select-using-elements-index

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!