Appium xpath contain follow not working
14,730
Solution 1
@Sahil Sehgal : Becuase your element doesn't have name attribute so you can use text attribute to find element. In the below example I have added check for "Available balance" and "INR". Use the one which suits your need -
driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'Available Balance')]")).click();
driver.findElement(By.xpath("//android.widget.TextView[contains(@text, 'INR')]")).click();
Solution 2
Search with the full text. Hopefully this will work.
driver.findElement(By.xpath("//android.widget.TextView[@text='INR 1,567.89']")).click();
Author by
Sahil Sehgal
Updated on June 05, 2022Comments
-
Sahil Sehgal almost 2 years
I am not able to use xpath contain and follow strategies in Appium. I dont know is it supported in Appium. Api level 19 . Can anyone please help: I have to click on Text View showing balance ie. INR ..... So i am using
driver.findElement(By.xpath("//android.widget.TextView[contains(@name,'INR')]")); and driver.findElement(By.xpath("//android.widget.TextView[contains(text(),'INR')]"));
but nothing works
-
Sahil Sehgal over 7 yearsthat is the main issue. I have tried with the above codes but it is not able to find element.
-
Suman over 7 yearsCan you post error logs? which one did you try? In the solution above, I am using @text not text()
-
Suman over 7 yearsin the above solution, xpath will work only for this balance (INR 1,567.89 ) when customer balance will change, test will fail.
-
Sahil Sehgal over 7 years,I suppose '@text' is not valid syntax in xpath
-
Akorna over 5 yearsAs weird as it seems, @text is correct syntax for xpath when it concerns Appium.