Reputation: 155
I am testing an Android hybrid app with selenium, appium, and RubyGems. When I try to click on an image on the page using
element = driver.find_element(:id => "image0")
element.click
I receive an error saying it cannot find the object. I then learned that I need to switch from Native App to WebView. When I try switching to Webview
driver.switch_to.window("WEBVIEW")
I receive an error saying "...Not yet implemented..."
So how do I switch to Web so I can click on the webelement and then switch back to Native_App using RubyGems?
Added... When I try driver.switch_to.context("WebView") I receive the error undefined method `context' for # (NoMethodError)
Any idea why I would receive the context error?
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
Upvotes: 0
Views: 8928
Reputation: 31858
Instead of your block :
driver.available_context
driver.switch_to.context("WebView")
Probably the correct way to do it as the docs suggests is :
Given(/^I switch to webview$/) do
webview = @driver.contexts.last
@driver.switch_to.context(webview)
end
Also make sure you switch to webview before trying to access any element on it and switch out of it before trying to access elements out of it.
Given(/^I switch out of webview$/) do
@driver.switch_to.context(@driver.contexts.first)
end
Upvotes: 0