0
down vote
favorite
I want to select a checkbox from a list of fruit names .
Eg .
1.Apple [ ]
2.Mango [ ]
3.Banana [ ]
This entire one row is in one relative layout , then text view and checkbox .
Relative layout[Parent]
//android.widget.TextView [@text=‘Mango’]
//android.widget.CheckBox [@text=‘liked’]
Now i have written function for selecting any fruit by clicking on checkbox , but my xpath is not returning any element.
public static void likeFruit(String fruitName){
driver.findElement(By.xpath("//android.widget.TextView [@text=’"+fruitName+"’]/following-sibling::android.widget.CheckBox[@text=‘liked’]")).click();
}
I have tried below xpath as well , nothing is working .Am i doing anything wrong?
1.//android.widget.TextView [@text=’"+fruitName+"’]/…/android.widget.CheckBox[@text=‘liked’] 2.//android.widget.TextView [@text=’"+fruitName+"’]/following-sibling::*[1]
TuHuynh
September 13, 2016, 7:05am
2
Maveric098:
'"+
Can you give a try of removing these thing?
Why ? This works fine .
If I use only //android.widget.TextView [@text=’"+fruitName+"’] element is found which taps on fruit name , not on the checkbox.
Am trying to click on checkbox not the fruit string .
No , it still shows NoSuchELement exception . My xpath is correct ?
1.//android.widget.TextView [@text=’"+fruitName+"’]/…/android.widget.CheckBox[@text=‘liked’] 2.//android.widget.TextView [@text=’"+fruitName+"’]/following-sibling::*[1]
TuHuynh
September 13, 2016, 8:16am
6
I think it should be better if you can have a UIAutomator screenshot and people can take a look.
Can you change ‘"+fruitName+"’ to “’”+fruitName+"’"
Gray circle is the checkbox
Ui Automator screenshot , blurred some sensitive data.
appV
September 28, 2016, 12:45pm
8
Can you get content-desc instead of text() for your element identification,
Try using below xpath, its working for me.
//android.widget.TextView [@content-desc=‘abc’]/following-sibling::android.widget.CheckBox