简体   繁体   English

使用 Xpath 找不到 WebElement

[英]WebElement cant be found with Xpath

I find the element with By.id, as the following code:找到带有By.id的元素,如下代码:

element = driver.findElement(AppiumBy.id(
    "com.test:id/product_detail_nav_host"
));

But none of this lines can find the same element:但是这些行都找不到相同的元素:

element = driver.findElement(AppiumBy.xpath(
    "//*[id='com.test:id/product_detail_nav_host']"
));
element = driver.findElement(AppiumBy.xpath(
    "//*[@id='com.test:id/product_detail_nav_host']"
));
element = driver.findElement(AppiumBy.xpath(
    "//*[resource-id='com.test:id/product_detail_nav_host']"
));

The first is errorprone as you are missing the @ before the keyword id第一个出错,因为您在关键字id之前缺少@


The third xpath is also errorprone as the value第三个xpath也是容易出错的值

com.test:id/product_detail_nav_host

is of the id attribute, but not the resource-id attribute.id属性,但不是resource-id属性。


However, the second code block looks flawless to me and should work perfecto:然而,第二个代码块在我看来完美无缺,应该可以完美运行:

element = driver.findElement(AppiumBy.xpath(
    "//*[@id='com.test:id/product_detail_nav_host']"
));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM