【发布时间】:2016-06-13 07:00:18
【问题描述】:
我正在测试一个带有 selenium、appium 和 RubyGems 的 Android 混合应用程序。当我尝试使用
单击页面上的图像时element = driver.find_element(:id => "image0")
element.click
我收到一条错误消息,说它找不到对象。然后我了解到我需要从 Native App 切换到 WebView。当我尝试切换到 Webview 时
driver.switch_to.window("WEBVIEW")
我收到一条错误消息“...尚未实施...”
那么如何切换到 Web 以便我可以单击 web 元素,然后使用 RubyGems 切换回 Native_App?
添加... 当我尝试 driver.switch_to.context("WebView") 我收到错误 # (NoMethodError) 的未定义方法 `context'
知道为什么我会收到上下文错误吗?
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,但我最终得到一个错误 undefined method `context' for #<:webdriver::targetlocator:0x000000050f8d40> (NoMethodError)
标签: android webview rubygems appium