我正在用selenium、appium和RubyGems测试一个Android混合应用程序。当我尝试使用
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”)时,我收到错误undefined method `context' for #(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
1条答案
按热度按时间tgabmvqs1#
而不是你的块:
可能正确的方法是docs建议的:
另外,请确保在尝试访问webview上的任何元素之前切换到webview,并在尝试访问webview中的元素之前切换出webview。