I'm new to Appium. Sorry if the question is duplicated, but I did not find the solution.
I have a problem - I cannot locate an element using Xpath, but I have no problems locating it using the ID locator. See the screenshot attached. The issue is reproduced not only for this element, but for all. It seems that Xpath does not work at all.
I'm using Appium 7.3.0 (tried different versions), UIAutomator2 by setting
I tried the following Xpath options:
- From the AndroidDriver level:
driver.findElement (By.xpath ("//*[@id='read_indicator']")); driver.findElement (By.xpath ("//android.widget.ImageView[@id='read_indicator']"));
- From the message element itself:
MobileElement message = driver.findElement (By.id ("body_bubble")); message.findElement (By.xpath (".//*[@id='read_indicator']")); message.findElement (By.xpath (".//android.widget.ImageView[@id='read_indicator']"));
- The same methods as above but starting from a frame layout with ID
footer_delivery_statusthat contains the required element directly.
But I can find the element without any difficulties using the ID locator:
driver.findElement (By.id ("read_indicator")); message.findElement (By.id ("read_indicator"));
Also, functions like
ends-with() etc. do not work too. Throws the following exception:
org.openqa.selenium.InvalidSelectorException: java.lang.IllegalArgumentException: Unable to compile '//*[contains(@id,'read_indicator')'
Also, I'm using
Thread.sleep where it is needed, so the elements should be present.
Please advice why I have such issues with Xpath.