Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium not starting portable chrome but local installation

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

like image 545
mario.schlipf Avatar asked Sep 28 '15 07:09

mario.schlipf


3 Answers

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);
like image 54
mario.schlipf Avatar answered Oct 04 '22 01:10

mario.schlipf


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) :).

like image 26
Max1234-ITA Avatar answered Oct 04 '22 00:10

Max1234-ITA


  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

like image 39
SeJaPy Avatar answered Oct 04 '22 00:10

SeJaPy