【问题标题】:Appium : Verify relative element presenceAppium:验证相对元素的存在
【发布时间】:2016-03-23 16:15:41
【问题描述】:

你能给个建议吗(请看图片)我如何检查 selectIndicator 是否存在于一个块上,然后我应该选择另一个。我知道如何检查该元素是否存在于整个页面上,但我需要查找它是否存在于特定元素上。在我的示例中,我选择了客厅,我需要检查是否未选择 DVR - 选择那个。知道我该怎么做吗?我试图以这种方式检查,但没有运气:

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

[http://i.stack.imgur.com/F98DM.png]

【问题讨论】:

  • 不是真正的重复。您的解决方案将检查页面上是否存在元素,这可以通过使用 isPresent 或 isDisplayed 来完成。但是我需要元素是否存在于特定的定位器(Xpath 或 id)上。知道如何实现吗?
  • 您可以尝试查找元素的属性并与预期的属性匹配,例如使用 WebElement w; w.getAttribute(arg0) w.getCssValue(arg0) w.getTagName()

标签: java android webdriver appium


【解决方案1】:

如果我没有误会您的意思,您希望实现一个自定义数据结构以获得适当的解决方案。这可能与此类似:

public class DVRList {
//declare components required to comprise one item
private String dvrOptionText ;
private boolean dvrOptionCheck ;
// implement setter..getter for these two
}

...in some method set the value using the logic
DVRList dvrlist = new DVRList();
WebElement parentOfBoth = driver.findElement(By.xpath("
//android.widget.RelativeLayout[1]/android.widget.R‌​elativeLayout[1]");
String text = parentOfBoth.findElementByAccessibilityId("First element").getText();
dvrlist.setdvrOptionText(text);
if(isElement(parenOfBoth.findElementByAccessibilityId("Second element"))
dvrlist.setdvrOptionCheck(true);
else dvrlist.setdvrOptionCheck(false);

然后您可以相应地使用这些参数。

注意:参数和方法是通用的,应根据具体目的进行修改。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 2021-05-04
    • 1970-01-01
    • 2016-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多