在下面的例子中,Appium能够正确地按类定位元素,但是当我们想要根据每个元素 content-desc 操作数据时,我们会看到一个错误。为什么我们无法获得content-desc的属性? 任何建议表示赞赏。
List<WebElement> arrayOfProperties2 = driver.findElementsByClassName("android.view.View");
List<WebElement> propertyMarkerEle = new ArrayList<>();
System.out.println("Found arrayOfProperties2 total: "+ arrayOfProperties2.size());
for (WebElement property : arrayOfProperties2){
String contentDesc = property.getAttribute("content-desc");
if (contentDesc.contains("property"))
propertyMarkerEle.add(property);
错误:找到arrayOfProperties2总数:32
org.openqa.selenium.NoSuchElementException:元素不能 位于页面上使用给定的搜索参数。 (警告: 服务器没有提供任何堆栈跟踪信息)
答案 0 :(得分:16)
使用&#34;名称&#34;
property.getAttribute("name");
答案 1 :(得分:1)
可以在boolean attrbutes和string attributes中找到已接受的属性名称列表。
布尔属性是:
字符串属性为:
我使用python绑定测试了这个。
答案 2 :(得分:0)
试试这个:
driver.findElement(By.AccessibilityID(""));
答案 3 :(得分:-1)
text
可以用作
driver.findElement(By.xpath("//*[@text='Remove Contact']"))
OR content-desc
可以用作
driver.findElement(By.name("Remove Contact"))
driver.findElement(By.xpath("//*[@content-desc='Remove Contact']"))
driver.findElement(By.name("Remove Contact"))