what to do when the resource-id of two elements in list view in UIAutomator of appium is same??
here in the images below:-
both the elements have same resource id:-net.one97.paytm:id/smart_list_root
what to do when the resource-id of two elements in list view in UIAutomator of appium is same??
here in the images below:-
both the elements have same resource id:-net.one97.paytm:id/smart_list_root
In this case, you can use xpath or name like below:
Way 1:
driver.findElement(By.xpath("//android.widget.TextView[@text='Mobile Prepaid']"));
driver.findElement(By.xpath("//android.widget.TextView[@text='Mobile Postpaid']"));
Way 2:
driver.findElement(By.name("Mobile Prepaid"));
driver.findElement(By.name("Mobile Postpaid"));
Get the text using xpath:
String text = driver.findElement(By.xpath("//android.widget.RelativeLayout")).getText();
Compare the text and select the correct UIElement to perform desired action.
if(text.equals("Mobile Prepaid")){
......
}
Take it with multiple elements for xpath for textview as
"//android.widget.TextView[@text='Mobile Prepaid']"
Hope it will work
You can use By.name like,
driver.findElement(By.name("Mobile Prepaid"));
driver.findElement(By.name("Mobile Postpaid"));
String ac = driver.findElement(By.xpath("(//*[@resource-id = 'account-balance-amount'])[1]")).getText();
String ac = driver.findElement(By.xpath("(//*[@resource-id = 'account-balance-amount'])[2]")).getText();