WebDriverIO使用元素索引选择 [英] WebDriverIO select using elements index
问题描述
我正在使用WebDriverIO在创建元素列表之后尝试访问(即getText,getAttribute,click等)元素。如果使用 browser.element()
方法,我很容易实现该元素,但是当我使用 browser.elements()
,我无法访问数组中的单个对象。根据 WebDriverIO文档,我应该能够使用<$ c访问它们$ c> value 属性。
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];
}
当我尝试使用第一个代码块时,它工作得很好。但是,当我尝试使用第二个块时,
会给我一个错误,提示 usingElements.click不是函数
或 usingElements。 getText不是函数
等。
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.
在使用browser.elements()方法后,如何隔离单个元素对象? p>
How can I isolate a single element object after using the browser.elements() method?
推荐答案
我想您可能需要使用以下两种方式之一:
I guess you might need to use one of the below two ways:
方式1:
var elmnts = browser.elements('.someCss');
var element = elmnts.value[0].ELEMENT;
browser.elementIdClick(element);
方法2:
var element = $$('.someCss')[0];
element.click();
谢谢,
Naveen
Thanks, Naveen
这篇关于WebDriverIO使用元素索引选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!