简体   繁体   中英

WebElement cant be found with Xpath

I find the element with By.id, as the following code:

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


The third xpath is also errorprone as the value

com.test:id/product_detail_nav_host

is of the id attribute, but not the resource-id attribute.


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']"
));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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