Selenium not starting portable chrome but local installation - google-chrome

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

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);

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

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

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

Related

PuppeteerSharp: Failed to launch Chromium

The error started to happen after updating google chrome to the latest version: 89.0.4389.82 (Official Build) (64-bit).
OS: Windows 10
Error:
PuppeteerSharp.ChromiumProcessException:
Failed to launch Chromium! [0309/160320.924:ERROR:os_crypt_win.cc(70)] Failed to encrypt: The system cannot find the file specified. (0x2)
Help, please!
I too got the same error while launching the chrome in the server using an application. I did upgrade google chrome manually and everything worked fine as normal.
after much faffing around trying to get this working in an asp.net app running in a production server environment (windows server 2019 in azure VM), i wanted to elaborate on vidya's answer "upgrade google chrome manually":
set the version number manually based on the latest version on this URL:
https://commondatastorage.googleapis.com/chromium-browser-snapshots/index.html?prefix=Win_x64/
in my case that version is 890410. set your code to use this version instead of DefaultChromiumRevision
const string ChromiumRevision = "890410";
var options = new BrowserFetcherOptions();
options.Path = HttpContext.Current.Server.MapPath("/App_Data");
var bf = new BrowserFetcher(options);
await bf.DownloadAsync(ChromiumRevision);
string exePath = bf.GetExecutablePath(ChromiumRevision);
var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
Headless = true,
ExecutablePath = exePath,
Args = new string[]{"--disable-gpu","--no-sandbox"}
});

EOFError, what happen to my minitest selenium test? how to fix it?

After my ubuntu updates, my minitest selenium test got an error, saying:
EOFError: EOFError: end of file reached
and it opens many blank google chrome windows as feature test total count.
my Ubuntu 16.04 updates was (yesterday everything works fine until the system made an update):
Commandline: aptdaemon role='role-commit-packages' sender=':1.105'
Upgrade: snap-confine:amd64 (1.0.42-0ubuntu3~16.04.1, 1.0.43-0ubuntu1~16.04.1), google-chrome-stable:amd64 (53.0.2785.143-1, 54.0.2840.59-1), ubuntu-core-launcher:amd64 (1.0.42-0ubuntu3~16.04.1, 1.0.43-0ubuntu1~16.04.1), libtracker-sparql-1.0-0:amd64 (1.6.2-0ubuntu1, 1.6.2-0ubuntu1.1)
in my test_helper.rb, I have:
Capybara.register_driver :selenium_chrome do |app|
Capybara::Selenium::Driver.new(app, :browser => :chrome)
end
Capybara.current_driver = :selenium_chrome
Capybara.javascript_driver = :selenium_chrome
Capybara.default_driver = :selenium_chrome
I tried to uninstall Google Chrome and used Chromium browser and it works fine.
I wanna know how to do it with Google Chrome browser.
Do somebody knows how to fix it?
Please help!
I'm not sure if this is going to help, but I asked a similar question here and was able to determine that I was using a gem called chromedriver-helper. That readme said to try running chromedriver-update within the rails app and that cleared everything up.

RemoteWebDriver with Chrome

I'm getting an error with connecting to my remote node and launching chrome via selenium.
My procedure:
start hub
start node with this bat:
java -jar selenium-server-standalone-2.41.0.jar -role node -hub
http://"hubadress":4444/register/grid
-Dwebdriver.chrome.driver="C:\Users\me\Downloads\chromedriver.exe"
then I run this code:
DesiredCapabilities dc = DesiredCapabilities.chrome();
Webdriver x = new RemoteWebDriver(new URL("http://'localhost':444/wd/hub"),dc);
which yields result: ...Path to driver executable must be set by the webdriver.chrome.driver system property.
I HAVE ALSO TRIED:
starting chromedriver on node
changing the localhost URL parameter in REMOTEWEBDRIVER to the adress of the node at port 9515 (port used for chromedriver)
Thank you so much for your time guys, I'm going insane and I need to troubleshoot some problems with firefox which works fine.
You are getting that for two possible reasons.
Reason 1
Your C:\Users\me\Downloads\chromedriver.exe does not exist. Make sure that THAT is the path.
Reason 2
The double quotes around the path might be exacerbating it. Take out the quotes to make it: -Dwebdriver.chrome.driver=c:\users\me\downloads\chromedriver.exe
Other than that, everything you have there is just fine. Make sure to address both of these reasons, and you should be golden.
You don't need to add "/wd/hub" to the url when using RemoteWebDriver
Also, I don't think that the sigle quote in you url is needed either:
http://'localhost':444/wd/hub
Oh god. The slashes were the wrong way.
Should have been:
java -jar selenium-server-standalone-2.41.0.jar -role node -hub
http://"hubadress":4444/register/grid
Dwebdriver.chrome.driver="C:/Users/me/Downloads/chromedriver.exe"

Selenium - Chrome is not starting when I try to load an extension

Since Firefox does not support the GWT DevMode any more, I want to switch to Chrome for developing selenium tests for my application.
However, it fails to load the GWT-dev-plugin extension. The test does not return from
driver = new ChromeDriver(capabilities);
Without configuring the extension, in works in the sense that a Chrome instance is at least started, however, without GWT plugin.
This is the way I configure the webDriver:
package the GWT plugin of your Chrome installation (described here http://www.mythoughts.co.in/2013/09/seleinum-webdriver-loading-chrome.html#.U0ZTFFfKGno)
use the path of the plugin .crx package as pluginPath in the following code
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(pluginPath));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
File driverExecutable = new File("test-selenium/chromedriver.exe");
System.setProperty("webdriver.chrome.driver", driverExecutable.getAbsolutePath());
driver = new ChromeDriver(capabilities);
The only logging is a WARNING concerning the plugin key:
[14.899][WARNING]: Public key in crx header is different from key in manifest
key from header: ....
generated extension id from header key: godampgacipeiboepncogmjpfbgcpfba
generated extension id from manifest key: jpjpnpmbddbjkfaccnmhnkdgjideieim

How can I launch Chrome with an unpacked extension?

I'm using Selenium WebDriver to test a Google Chrome extension I'm developing. I noticed that ChromeDriver can be customised to add extensions to the instance of Chrome that it launches. This can be achieved using the AddExtension and AddExtensions methods of the ChromeOptions class.
The documentation for these methods indicates that they require extensions to be provided as crx files. Since I'm developing the extension, I don't have a crx file. I would like to be able to load the unpacked extension, but I couldn't find a method to do this.
I tried putting the extension files in a zip file and specifying this for the AddExtension method, but this caused an exception to occur since it wasn't a crx file. I also tried passing in the directory containing the unpacked files, but this produced a FileNotFoundException.
How can I do this?
I was able to achieve this by using the AddArgument method to directly pass the information to Chrome. Here's what it looks like in C#:
options = new ChromeOptions();
options.AddArgument("--load-extension=" + unpackedExtensionPath);
For packed extensions (a .crx file)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
For unpacked extensions (a local folder)
ChromeOptions options = new ChromeOptions();
options.addArguments("load-extension=/path/to/extension");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
source
It may be late but for future users:
https://sites.google.com/a/chromium.org/chromedriver/extensions
The unpacked extension error popped up for me and I requested for removing the restrictions in chrome which was enforced as organizational policy. Once the restrictions were removed, I am able to run the program with out any errors. ChromeBrowser-GPO-Deny - this was the one which was removed. You can check in Settings - Extensions - Check on Developer mode and see if the load unpacked extensions is checked once the restrictions are removed. You should be good then. All the above will work only when the chrome is not restricted.
In Python3 it can be done like this:
from selenium.webdriver import Chrome, ChromeOptions
options = ChromeOptions()
options.add_argument("load-extension=/path/to/unpacked_ext")
driver = Chrome("/path/to/chromedriver", options=options)
# (optional) Look at the uploaded extension
driver.get("chrome://extensions")
Here is apython example using webdriver_manager
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
# loading the extension Edit-This-Cookie
options.add_argument("--load-extension=./Edit-This-Cookie")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=options)
driver.get("https://google.com")
The Selenium documentation has an example like this for a packed ( not unpacked) extension:
capabilities.setCapability("platform", "Windows 8" );
capabilities.setCapability("version", "10");
capabilities.setCapability("name", testname);
capabilities.setCapability("screen-resolution", "1280x1024");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
if (isLocal) driver = new ChromeDriver(capabilities);