android - Appium locating child element with specific value in Java -
i struggling navigation drawer on native android app.
so there 11 elements in drawer, 9 visible, rest have scroll down.
those elements contain 2 child elements, first - imageview, second - textview element.
what want do, create method iterate through visible drawer elements in search element specific name , tap on it, if elements invisible, scroll drawer down/up , repeat iteration.
so need loop iterate through textview elements, locate 1 need using text attribute , click on parent element of textview.
however i'm struggling locating elements using xpath , appium can not seem find them.
can me understand how specify xpath dynamically can iterate through elements?
thank you.
you try have below. uses pageobject model, along selenium , appium. takes advantage of uiautomator, rather xpath.
public class pageobjectxyz { private androiddriver driver; @androidfindby(uiautomator = "new uiselector().classname("android.widget.textview")") private list<mobileelements> sometextviews; public pageobjectxyz(androiddriver driver) { this.driver = driver; pagefactory.initelements(new appiumfielddecorator(driver), this); } public void clicktheoneiwant(string option){ for(mobileelement me: sometextviews){ if(me.getattribute("text").equals(option)){ this.driver.tap(1, me, 1000); break; } } } }
if want quick , dirty using xpath, like(some assembly may required):
string x = "//recyclerview/relativelayout/relativelayout/textview"; string y = "//recyclerview/relativelayout/relativelayout"; android driver = new androiddriver(new url("http://localhost:4723/wd/hub"), desiredcapabilities); arraylist<mobileelements> arraytextviews = driver.findelementsbyxpath(x); arraylist<mobileelements> arrayparentelements = driver.findelementsbyxpath(y); for(int = 0; < arraytextviews.size(); i++){ if(arraytextviews.get(i).gettext().equals("text want")){ arrayparentelements.get(i).click(); } }
Comments
Post a Comment