Hybrid App - chrome driver fails to find chrome

Hi there!
I’m relatively new to using appium/webdriver tech; I’m trying to automate an app on android (real device) that launches a broswer and after switching contexts the driver fails with an error:
Error: Failed to start Chromedriver session: An error occurred (Original error: chrome not reachable
[Chromedriver] (Driver info: chromedriver=2.37.544337 (8c0344a12e552148c185f7d5117db1f28d6c9e85),platform=Mac OS X 10.13.4 x86_64))
[Chromedriver] at Object.wrappedLogger.errorAndThrow (/usr/local/lib/node_modules/appium/node_modules/appium-support/lib/logging.js:78:13)
[Chromedriver] at Chromedriver.callee$2$0$ (/usr/local/lib/node_modules/appium/node_modules/appium-chromedriver/lib/chromedriver.js:411:13)
[Chromedriver] at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
[Chromedriver] at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
[Chromedriver] at GeneratorFunctionPrototype.prototype.(anonymous function) [as throw] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
[Chromedriver] at GeneratorFunctionPrototype.invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)

I am using chromedriver 2.37.544337 Appium 1.8.1 and can manually interact with the chrome browser on the phone using the chromedriver
I did notice that the desired capabilities are assuming I’m still in my app when launching the same android package instead of chrome. . . could that be the problem? Is there a way to interact with that without changing appium code?

Any advice would be much appreciated!

Check what version of chrome you have on your phone / emulator

adb shell dumpsys package com.android.chrome | grep versionName

Then take a look at this page to see if your version of chrome is just too old for chromedriver 2.37

If it’s too old, you’ll have to download the older chromedriver, and then specify the chromedriver to use when starting up appium:

--chromedriver-executable <path_to_chromedriver>

I figured it out finally!
instead of switching contexts, which was failing, I ended up just switching activities -

self.web_driver.start_activity('com.android.chrome', 'com.google.android.apps.chrome.Main')

and switching back once I was done

Hi @kamaroyl… I’m also new to appium so could you share your code for opening chrome?

Hi Avinash!

The code I posted was all I had to do. I’m interacting with hockey app, which launches the chrome app initially, then I use

def _web_app(self, username, password): try: self.web_driver.start_activity('com.android.chrome', 'com.google.android.apps.chrome.Main') _log.info("switched to chrome") sleep(5) information = self.web_driver.find_element_by_xpath("//*[@text='INFORMATION']").is_enabled() if not information: _log.info("need to log in") self.web_driver.find_element_by_xpath("//*[@text='Email']").send_keys(username) self.web_driver.find_element_by_xpath("//*[@text='Password']").send_keys(password) self.web_driver.find_element_by_xpath("//*[@text='Sign In']").click() sleep(5) _log.info("clicking authorize") self.web_driver.find_element_by_xpath("//*[@text='Authorize']").click() _log.debug("clicked authorize") return True except NoSuchElementException: _log.error("No element found for login") return False

I found Chrome’s package and Name through some quick googling, though you can always do a dumpsys

Note, I am using Android. If I get ios working I will give an update

1 Like