【问题标题】:Seetest Automation MobileWebDriver find element by xpathSeetest Automation MobileWebDriver 通过 xpath 查找元素
【发布时间】:2017-01-13 01:58:19
【问题描述】:

我正在使用来自 experitest.com 的 Seetest Automation,更准确地说,我正在使用 Seetest Automation 的 MobileWebDriver 实现,正如 experitest 所说“...对于移动浏览器 [...],它还可以用于自动化 Native应用程序”。

所以,我在 Seetest 下启动我的检测应用程序,然后打开检查器“object spy”。这个检查器非常酷,因为您可以单击应用程序的某些屏幕元素,检查器将自动在 DOM 中显示节点及其所有属性。检查器可以验证屏幕 DOM 的 xpath 表达式,因此您可以轻松验证 xpath 表达式对于您正在寻找的元素是否正确。

我有一个 xpath://*[@text='Login']

该 xpath 已通过 object spy 验证,它能够找到我正在寻找的元素。

所以,我验证了按钮的 xpath 表达式,下面是执行点击的 Seetest 客户端:

MobileWebDriver driver = new MobileWebDriver("localhost", 8889);
driver.client.setDevice(mydevice.ID);
// Launch instrumented app
driver.client.launch(myapp.activity, true, true); 

driver.findElementByXPath("//*[@text='Login']").click();

前四行不正常。有问题?遗漏了什么? ¿ 仪表化与未仪表化?

前四行的例外:

com.experitest.client.InternalException: Exception caught while executing click: Element was not identified: 'xpath=//*[@text='Login']' at zone NATIVE

我正在使用 Seetest 的 MobileWebDriver 实现,因为我需要与一些 selenium/appium 代码兼容/集成。

谢谢,希望有人知道!

【问题讨论】:

    标签: java android selenium xpath automation


    【解决方案1】:

    问题在于查找元素的目标“区域”或“上下文”。 MobileWebDriver 默认使用 NATIVE 区域。我的应用程序也是一个使用 Web 组件的混合应用程序,而我正在寻找的元素是一个 Web 元素。

    所以,解决方案是使用 MobileWebDriver 的这种方法:

    ((MobileWebDriver) driver).useWebIdentification();
    

    这允许驱动程序查看 WEB 区域而不是 NATIVE。

    还有另一种方法可以检查 NATIVE 中的元素:

    ((MobileWebDriver) driver).useNativeIdentification();
    

    简单的解决方案。希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 2020-05-03
      • 2020-07-20
      • 2016-03-12
      • 2017-09-14
      • 2014-08-07
      • 1970-01-01
      • 2020-08-08
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多