我正在使用混合應用程序並在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! –