【问题标题】:Problem clicking elements using class and index使用类和索引单击元素时出现问题
【发布时间】:2019-02-24 17:24:46
【问题描述】:

我正在尝试编写代码以自动在 Instagram 上向人们发送 DM。我坚持让代码点击 DM 按钮。

在 UIautomatorviewer 中,没有文本或资源 ID,所以我尝试使用该类。

当我运行代码时,它没有点击正确的东西。它点击按钮 NEXT 到它。

这里是代码 -

By path2 = By.xpath("//android.widget.ImageView[@index='3']"); 
driver.findElement(path2).click(); 
Thread.sleep(5000);

有人可以帮忙吗?我是新手,所以我不是很有经验。

【问题讨论】:

    标签: java android selenium automation appium


    【解决方案1】:

    因为我看不到整个 XML,我无法真正说出你做错了什么,但可能你的 xpath 不正确。 使用 UIAutomatorViewer,您可以保存 XML,然后您可以在其上测试您的 xpath。使用 XMLSpy 或 https://www.freeformatter.com/xpath-tester.html 等在线工具。

    可能有更多的 index = 3 的 android.widget.ImageView 并且我认为 appium 选择了第一个?因此,您可以将 xpath 更改为更独特的路径,例如:

    //android.widget.FrameLayout//android.widget.LinearLayout//android.widget.ImageView[@index='3']"
    

    【讨论】:

      【解决方案2】:

      基于 UIAutomator Viewer 屏幕,您还可以使用content-desc,如下所示

      By path2 = By.xpath("//android.widget.ImageView[contains(@content-desc,'Message')]");
      driver.findElement(path2).click();
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-12
        • 1970-01-01
        • 2011-02-01
        • 1970-01-01
        • 2020-08-08
        • 1970-01-01
        相关资源
        最近更新 更多