gpt4 book ai didi

android - 无法使用 Android WebDriver 操作 IFrame 中的点击

转载 作者:行者123 更新时间:2023-11-30 02:38:28 24 4
gpt4 key购买 nike

我正在为混合应用程序编写测试,该应用程序在 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 模拟器上尝试过它——它们都不起作用。

最佳答案

好吧,我设法解决了这个问题。我使用 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()

关于android - 无法使用 Android WebDriver 操作 IFrame 中的点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26146795/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com