selenium RemoteWebDriver opens but ChromeOptions are not passed to Selenium Grid

3.9k Views Asked by At

I have been trying to resolve a few issues with RemoteWebDriver and ChromeOptions using docker and selenium grid. The main issue is with the proxy but I half resolved that with a proxy pac file passing the pac file url as an arg into ChromeOptions. The below code runs great in docker debug and standalone locally but as soon as I try with the grid or deploy and run with bamboo the driver opens and I can see that ChromeOptions are not being passed because the poxy pac file is not being used and it's just frozen at org.openqa.selenium.remote.ProtocolHandshake createSession. I have been researching for a few weeks now and I am at a hard blocker with this now. I have seen some posts that DesiredCapabilities is deprecated but I have not found a way to implement ChromeOptions without it.

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("--disable-infobars");
    options.addArguments("--proxy-pac-url= http://ProxyPacURL.com");
    DesiredCapabilities dc = DesiredCapabilities.chrome();
    dc.setCapability(ChromeOptions.CAPABILITY, options);
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), dc);
3

There are 3 best solutions below

0
On

I was facing same issue and I have found the solution as below: We need to set "goog:chromeOptions" instead of "chromeOptions".

In your Java code, following line is present:

dc.setCapability(ChromeOptions.CAPABILITY, options);

If you navigate to ChromeOptions.CAPABILITY, you will notice that it is a constant with value "chromeOptions". This works fine for local web driver, but not for remote web driver (i.e. selenium grid).

Just change above line to this:

dc.setCapability("goog:chromeOptions", options);

Now when you execute your Java code, it will work fine and all your options will show their effect too.

I came across other pages, such as this, which referred to above solution.

1
On

Update to latest Selenium Jars, make sure your java is version 1.8 or greater, then you can pass ChromeOptions into the driver because DesiredCapabilities is deprecated. I am now able to run selenium docker nodes with selenium grid and all ChromeOptions arguments are now being passed to the containers.

    ChromeOptions options = new ChromeOptions();
    options.addArguments("--start-maximized");
    options.addArguments("--disable-infobars");
    options.addArguments("--proxy-pac-url=http://myPacFile.com");
    options.addArguments("--no-sandbox");
    driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), options);
0
On

Try this:

const GRID_HOST = 'http://localhost:4444/wd/hub';

var options = new chrome.Options();
options.addArguments("--start-maximized");
options.addArguments("--disable-infobars");
options.addArguments("--proxy-pac-url=http://myPacFile.com");
options.addArguments("--no-sandbox");

driver = new webdriver.Builder()
.usingServer(GRID_HOST)
.forBrowser("chrome")
.setChromeOptions(options)
.build()