无法通过 getAttribute 获取“索引"节点详细信息 [英] Cannot get 'index' node detail by getAttribute
本文介绍了无法通过 getAttribute 获取“索引"节点详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 Appium 自动化的新手,我正在尝试通过在我的代码中使用 .getAttribute 来检索索引"节点值,但我无法做到.有什么方法可以检索特定元素定位器的索引吗?
I am new to Appium automation and I'm trying to retrieve 'index' node value by using .getAttribute in my code but am not able to. Is there any way that i can retrieve index of a particular element locator?
String x = driver.findElement(By.xpath("//android.widget.TextView[@text='"+str+"']/../..")).getAttribute("index");
推荐答案
你不能使用 getAttribute()
方法检索索引值,而是使用类似计数器的东西来识别文本的次数字段出现在屏幕上.
You cannot retrieve index value using getAttribute()
method, instead use something like a counter to identify the number of the times the text field occurs on the screen.
By mySelector = By.xpath("//android.widget.TextView");
List<WebElement> myElements = driver.findElements(mySelector);
int count = 0;
for(WebElement e : myElements) {
count++;
if(e.getText().equals(str1)) {
System.out.println(count); //This will give the index value
}
else{
//do something else
}
}
这篇关于无法通过 getAttribute 获取“索引"节点详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文