【问题标题】:Unable to manipulate click in IFrame using Android WebDriver无法使用 Android WebDriver 在 IFrame 中操作点击
【发布时间】:2014-11-26 14:44:22
【问题描述】:

我正在为在 webview 中包含 iframe 的混合应用程序编写测试,并且我正在尝试单击 iframe 中的按钮。

值得一提的是,iframe 内的数据来自另一个来源。尽管如此,我还是设法切换到 iframe,并且可以看到它的内容(也正在获取元素)。

这是我运行的命令序列

return driver
  .contexts().then(function (contexts) { 
    return browser.context(contexts[1]); // choose the webview context
   }) 
  .frame('myFrame") //switch to iframe
  .getElementById('myButton')
  .click() //try to click button

它在 iOS 模拟器上运行良好,但在 Android 上它什么也不做。测试继续运行,但未执行任何操作。

我正在使用 nodejs wd 客户端和 Genymotion 2.2.2 运行 Appium 1.2.2 我还在真正的 android 设备和 Andorid SDK 模拟器上进行了尝试——它们都不起作用。

【问题讨论】:

    标签: android node.js iframe appium


    【解决方案1】:

    好吧,我设法解决了这个问题。我使用 xpath 来查找元素,然后使用 tapElement() 使魔法发生。

    return driver
      .contexts().then(function (contexts) { 
        return browser.context(contexts[1]); // choose the webview context
      }) 
      .frame('myFrame") //switch to iframe
      .elementByXPath('//li[div/span[contains(text(),"Data I want")]]')
      .then(function(el){
        return driver.tapElement(el);
      })
    

    我在appium's github 中打开了一个关于它的问题,并且还将在 wd 的 github 中打开一个。

    更新:

    您可以使用.tap()链接元素方法:

      .elementByXPath('//li[div/span[contains(text(),"Data I want")]]')
      .tap()
    

    【讨论】:

      猜你喜欢
      • 2023-03-22
      • 2016-08-26
      • 2023-03-22
      • 2018-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-29
      • 2022-01-20
      相关资源
      最近更新 更多