我正在使用混合应用程序并在Ruby中使用Appium + Selenium Webdriver编写测试。Selenium Webdriver(Appium) - 在混合应用程序(iOS)中切换到UIWebview
我开始测试一些文本编辑+点击一个按钮来打开UIWebview(到目前为止一切正常)。问题是当UIWebview打开时 - 我无法访问它(当我尝试点击一个html元素时(我正在使用Appium检查器来查找元素并记录我的Ruby测试),它立即关闭。我知道我有切换到一个UIWebView(因为我发现here),但我不能让它工作
代码示例:
require 'rubygems'
require 'selenium-webdriver'
capabilities = {
'browserName' => 'iOS',
'platform' => 'Mac',
'version' => '7.1',
'device' => 'iPhone Retina (4-inch)',
'app' => '/Users/{my user here}/Library/Developer/Xcode/DerivedData/{path here}/Build/Products/Debug-iphonesimulator/SDK.app'
}
server_url = "http://127.0.0.1:4723/wd/hub"
@wd = Selenium::WebDriver.for(:remote, :desired_capabilities => capabilities, :url => server_url)
# ...
# Do all kind of native actions here
# ...
@wd.find_element(:name, "showWebviewButton").click
@wd.manage.timeouts.implicit_wait = 30 # seconds
# ???
# How do I switch to my UIWebview here???
# (cannot access html elements here with @wd.find_element(:name, "htmlElement"))
# ???
@wd.quit
编辑: 使用Appium检查我发现我的UIWebView是“窗口(1)“,所以我试过了:
@wd.switch_to.window(1)
这给我的错误:
A request to switch to a different window could not be satisfied because the window could not be found
(加载的UIWebView之前抛出的错误)
好的,tnx。这似乎是合理的,但正如你所看到的 - 我打算在打开Webview之前等待30秒。你有什么想法我在这里做错了什么? TNX! –