Hello,
I have an application homepage and I the appium script is not able to find the element using the ID at runtime:
@FindBy (how=How.XPATH,using=("//android.widget.TextView [@text=‘FamilyProfile’]")) WebElement Family_Profile;
I have a few observations that I would like to share:
The argument in the text view and the text differs
When I generate the source during runtime, I have observed that for this element is being translated as “Family
Profile”
I have also tried using
@FindBy (how=How.XPATH,using=("//android.widget.TextView [@text=‘Family
Profile’]")) WebElement Family_Profile;
and
@FindBy (how=How.XPATH,using=("//android.widget.TextView [@text=‘Family’]")) WebElement Family_Profile;
If you would please advice on the same, that would be great!
@supratimdutta
You can use ‘contains()’ method.
@FindBy(how=How.XPATH,using=("//android.widget.TextView[contains(text(),‘Family’)]"))
WebElement Family_Profile;
UD
July 27, 2017, 5:55am
4
For text property, use text() than @text
@FindBy (how=How.XPATH,using=(“//android.widget.TextView [text() =‘Family Profile’]”))
WebElement Family_Profile;
If you still have some problem prefer using text property with contains like below:
@FindBy (how=How.XPATH,using=(“//android.widget.TextView [contains(.,‘Family Profile’)]”))
or
@FindBy (how=How.XPATH,using=(“//android.widget.TextView [contains(text(),‘Family Profile’)]”))
WebElement Family_Profile;
Let us know if any of the above didnt work out.
but best and fastest for android is native method:
String text = "your_text";
List<WebDriver> elementList = ((AndroidDriver) driver).
findElements(MobileBy.AndroidUIAutomator("new UiSelector().textContains(\"" + text + "\")"));
// or
@AndroidFindBy(uiAutomator = "new UiSelector().textContains(\" your_text \")")
1 Like
I tried this, this does not work:
Hello Aleksei,
This also does not help:
Code used: @AndroidFindBy (uiAutomator = “new UiSelector().textContains(” Family “)”) WebElement Family_Android_Findby;
Your search text in code has blank. Maybe this issue. If not it means there is no element which has this text as value. Sometimes it goes to another attribute. Check with inspector where your search text is.
hi @supratimdutta ,
i think you should try this: -
driver.findElementByAndroidUIAutomator(“new UiSelector().textContains(“Family”).textContains(“Profile”)”).click();
Hope so, it will work for you.
harry
January 25, 2020, 6:39pm
11
I tried but didn’t work. Using Appium 1.15.1
@AndroidFindBy (uiAutomator = “new UiSelector().textContains(‘Introducing Family’)”)
public MobileElement syncText;
Please let me know what’s wrong in this.
1 Like
Aleksei
January 25, 2020, 10:06pm
12
Try again but with \" instead of '.
So it will be:
@AndroidFindBy(uiAutomator = "new UiSelector().textContains(\"Introducing Family\")")
public MobileElement syncText;
1 Like
harry
January 27, 2020, 10:47pm
13
Yaaaa it worked. Thanks u Sir.
harry
January 27, 2020, 11:12pm
14
It was my mistake. Sorry for this.
Hi, i have the same probem and i tried your solution, but it works only with webElement in web View.
Is it normal? What can i use for android element?