我正在測試具有硒,appium和RubyGems的Android混合應用程序。當我嘗試點擊圖片使用如何使用Appium和RubyGems從NativeApp切換到WebView
element = driver.find_element(:id => "image0")
element.click
在頁面上我收到一個錯誤說,它不能找到對象。然後我知道我需要從Native App切換到WebView。當我嘗試切換到的WebView
driver.switch_to.window("WEBVIEW")
我收到一個錯誤說「......尚未實現......」
那麼,如何切換到Web,以便我可以點擊webelement然後切換使用RubyGems返回Native_App?
加... 當我嘗試 driver.switch_to.context( 「的WebView」) 我收到錯誤 未定義的方法`上下文」爲#(NoMethodError)
任何想法,爲什麼我會收到上下文錯誤?
require 'rubygems'
require 'selenium-webdriver'
require 'uri'
require 'appium_lib'
require_relative 'SDK_Navigation'
mySampleApp = SampleApp.new
myNavigation = Navigation.new
myProducts = Products.new
myProductEditor = ProductEditor.new
caps = Selenium::WebDriver::Remote::Capabilities.android
caps['deviceName'] = 'fegero'
caps['platformName'] = 'Android'
caps['app'] = 'C:\Users\ScottFeger\Downloads\SampleApp_1105.apk'
driver = Selenium::WebDriver.for(
:remote,
:url => "http://127.0.0.1:4723/wd/hub",
:desired_capabilities => caps)
mySampleApp.PickImagebtn(driver)
mySampleApp.SelectAlbum(driver, "All Photos")
mySampleApp.SelectImage(driver,"bob")
myNavigation.SelectParent(driver, "Home & Office")
myNavigation.SelectChild(driver, "Home Decor")
myProducts.SelectProduct(driver,"Coasters")
myProductEditor.AddPhoto(driver)
#================================================================
#WEBVIEW - Where my problem begins
#driver.execute_script 'mobile: tap', x: 150 , y: 300 // WORKS
driver.available_context
driver.switch_to.context("WebView")
#Click on an image
element = driver.find_element(:id => "image0")
element.click
我曾嘗試改變.window到.context,但我最終得到一個錯誤未定義的方法'上下文」爲#<硒:: webdriver的:: TargetLocator:0x000000050f8d40>(NoMethodError) – user3531858