In my current Application, the scenario is as below:-
- Open Chrome and set the url
- Click on a button => Message composer opens up with content and number pre-filled.
- Validate the contents and number of the Message.
Once the button is clicked, it seems that Appium is not able to connect to the Message composer opened by the Button click. Is it possible to switch control to the composer and validate the contents etc?
Referring to your scenario, I feel you are switching from webapp context to nativeapp context.
Did you try switching to nativeapp context? If not try switch to the native app by referring the below code.
Set<String> contextNames = driver.getContextHandles();
for (String contextName : contextNames) {
System.out.println(contextNames); //prints out something like NATIVE_APP & WEBVIEW_1
}
And then switch to native context using below code and then try fetching the values.
driver.context("NATIVE_APP");
Let me know if it works for you.
~
Raghavendra
Thanks for the code.
Since I am using Ruby, tried using the corresponding “available_contexts” method but got an error saying no such method.
Code as below:-
require 'rubygems'
require 'appium_lib'
require 'selenium-webdriver'
puts "Setting Capabilities"
caps = {
'version' => '4.x',
'device' => 'android',
'deviceType' => 'phone'
}
@driver = Selenium::WebDriver.for(
:remote,
:url => "http://127.0.0.1:4723/wd/hub",
:desired_capabilities => caps)
@driver.get("SAMPLE URL")
sub_btn = @driver.find_element(:xpath, "//div[@id='one_click']/a")
clickHere_lnk = @driver.find_element(:xpath, "//div[@id='clickHere']/a")
if (clickHere_lnk.attribute(@href) == sub_btn.attribute(@href))
puts "PASS"
else
puts "FAIL"
end
@driver.save_screenshot "D:/Appium_Demo/Screenshots/1.png"
sub_btn.click
contextNames = @driver.available_contexts
puts contextNames
Error:-
real_device_android_wapsite.rb:42:in <main>': undefined method
available_contexts’ for #<Selenium::WebDriver::Driver:0x5bc71ab6 browser=:chrome> (NoMethodError)
Even tried using an Appium driver instead of the selenium web driver.
Still getting this error:-
C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/common.rb:66:in `create_response': unexpected response, code=404, content-type="text/plain" (Selenium::WebDriver::Error::WebDriverError)
unknown command: session/82a2d73c74f15fac4463dce9620c71d5/contexts
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/default.rb:66:in `request'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/http/common.rb:40:in `call'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:638:in `raw_execute'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/selenium-webdriver-2.43.0/lib/selenium/webdriver/remote/bridge.rb:616:in `execute'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/appium_lib-4.1.0/lib/appium_lib/device/device.rb:106:in `available_contexts'
from trial_real_device_android_wapsite.rb:25:in `<main>'