Appium, Android - Finding element inside another e

2019-06-01 05:44发布

I am trying to check if element exist, but appium seems to ignore searching an element when we specified that it should be inside another element. For example:

driver.findElementByAccessibilityId("First element").findElementByAccessibilityId("Second element");

It should work somehow since there is option in Appium inspector called Locator where after selecting strategy and choosing search from selected element option it finds what I expect.

What is the proper way of finding such elements ?

3条回答
\"骚年 ilove
2楼-- · 2019-06-01 05:57

Simple solution but not the cleanest below:

I am using TestNG framework which I suppose do not allow declarations such as

private WebElement element= driver.findElementByAccessibilityId("First element").findElementByAccessibilityId("Second element");

Simple solution but not the best is to declare only parents as:

@FindBy(name="Parent")
private WebElement ParentElement;

Then in test case for example:

ParentElement.findElement(By.name("childElement")).isDisplayed())
查看更多
Explosion°爆炸
3楼-- · 2019-06-01 06:08

Put the first element as parent and second element as child -

 MobileElement parentButtonList = (MobileElement)driver.findElementById(parentClassIdentifier);
List<MobileElement> childButtonList = parentButtonList.findElementsById(childClassIdentifier);
查看更多
趁早两清
4楼-- · 2019-06-01 06:12

You can use a xpath for the same. Sample xpath for the situation will be like :

driver.findElement(By.xpath("//*[@accessibility-id='FirstElement']//*[@accessibility-id='FirstElement']"))

The // between first element and second element indicates first element is the base element for start searching the second element. So it will search for the second element between the scope of the first element

查看更多
登录 后发表回答