10

I have a problem with the Selenium web driver. What I'm trying to do is to start a "portable" chrome instead of my local installation, because it has different settings.

The problem is that the portable Chrome (from PortableApps) seems to only start when using GoogleChromePortable.exe. If I use the Chrome binary directly, it will start my local installation. With Selenium it seems that no matter what Chrome path I pass to it (GoogleChromePortable.exe or binary path), it starts my local installation.

Here is my code:

String chromePath = "M:/my/path";
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
capabilities.setCapability("chrome.binary", chromePath);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);

Any ideas how to be able to start my portable chrome? Thanks

mario.schlipf
  • 1,257
  • 2
  • 13
  • 29

4 Answers4

7

For anyone else stumbling upon this problem, here is how I managed to get the portable Chrome starting:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setBinary(binaryPath);
driver = new ChromeDriver(chromeOptions);
mario.schlipf
  • 1,257
  • 2
  • 13
  • 29
4

I'm using Python 3.7 on Windows 10 and got Chrome Portable from PortableApps.com.

comments by @mario.schlipf and @SeJaPy were helpful, but I noticed that in the newer Webdriver releases, the setbinary method has been replaced by binary_location

This is how it actually worked for me:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chromedriverpath='M:/my/chromedriver.exe'
chromePath = 'M:/my/App/Chrome-bin/chrome.exe'    #  <==  IMPORTANT! See note below.

chromeoptions = Options()
chromeoptions.add_argument('--incognito')
chromeoptions.binary_location = chromePath   

browser = webdriver.Chrome(executable_path=chromedriverpath, options=chromeoptions)

NOTE:

The chromePath variable must point to the Chrome executable in the portabilized environment.

In packages obtained from PortableApps.com, you have two executables: a GoogleChromePortable.exe in the install (actually, unpack) directory and a chrome.exe in [installdirectory]/App/Chrome-bin, the first being "just" a launcher which provides the portabilized app with a consistent environment.

As I could observe, chromedriver needs to directly interact with the "real" Chrome executable, otherwise the script will launch the browser (via the launcher) but will eventually crash with error message:

unknown error: DevTools Active Port file doesn't exist

and no browser session will be returned as a result.

This may seem obvious to many people... but it was not to me, so I decided to put this note in order to make some clarity for the less clever guys (myself included) :).

Max1234-ITA
  • 147
  • 1
  • 1
  • 8
  • 1
    Thanks. `[installdirectory]/App/Chrome-bin` was helpful and resolved my issue. I was just referencing `GoogleChromePortable.exe`, which produced an error: [Failed to load extension... Manifest file is missing or unreadable](https://i.stack.imgur.com/1b3bx.jpg), even though I wasn't loading any extensions. – howdoicode Aug 27 '20 at 14:26
2
  String chromePath = "M:/my/googlechromeporatble.exe path"; 
  String chromedriverpath="M:/my/chromedriver.exe path";
  ChromeOptions options = new ChromeOptions();
  options.setBinary(chromepath);
  System.setProperty("webdriver.chrome.driver",chromedriverpath);              
  driver = new ChromeDriver(options);

This will invoke portable chrome rather than local installation. First set google chrome portable path and then invoke chromeriver.exe

SeJaPy
  • 284
  • 1
  • 6
  • 18
0

Depending on the settings you have in ChromePortable, maybe you could default ChromeDriver with Capabilities & ChromeOptions?

I'm thinking especially on custom profile. If you somehow could get that from your ChromePortable and load it with default ChromeDriver?

EDIT: Maybe this could help

Community
  • 1
  • 1
terle
  • 86
  • 10