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();
Share:
14,730
Sahil Sehgal
Author by

Sahil Sehgal

Updated on June 05, 2022

Comments

  • Sahil Sehgal
    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

    enter image description here

  • Sahil Sehgal
    Sahil Sehgal over 7 years
    that is the main issue. I have tried with the above codes but it is not able to find element.
  • Suman
    Suman over 7 years
    Can you post error logs? which one did you try? In the solution above, I am using @text not text()
  • Suman
    Suman over 7 years
    in the above solution, xpath will work only for this balance (INR 1,567.89 ) when customer balance will change, test will fail.
  • Sahil Sehgal
    Sahil Sehgal over 7 years
    ,I suppose '@text' is not valid syntax in xpath
  • Akorna
    Akorna over 5 years
    As weird as it seems, @text is correct syntax for xpath when it concerns Appium.