1

I'm using selenium and chromedriver to control some chrome instances under debian linux. I would like to make these chrome instances headless and i also would like to start them on different virtual displays via Xvfb which have different display-resolutions.

My java/selenium code works perfekt using the chrome binary directly (non-headless). Strictly speaking the chrome binary (/usr/bin/google-chrome) is also only a wrapper script which is in the path. Using my self-made chrome wrapper script (and set it as binary in chromeOptions, like described here: https://sites.google.com/a/chromium.org/chromedriver/capabilities ) it doesn't work and fails with: unknown error: Chrome failed to start: exited abnormally

I think the reason is my wrapper script. What is wrong or what should i improve? This is the script:

#!/bin/bash
export DISPLAY=:1920
cd /usr/bin/
google-chrome "$@"

The java-code which sets the wrapper script as chrome binary via chromeOptions:

// set custom binary
ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/executable-wrapper-script");

Please remind that the Xvfb displays are running, so that's not the problem. I tested them with x11vnc and i also get chrome started on them, calling the wrapper script directly in my shell.

whitenexx
  • 1,350
  • 2
  • 25
  • 53

1 Answers1

1

I solved the main-problem so the workaround within the question isn't needed anymore. As already described here ( https://groups.google.com/forum/#!topic/chromedriver-users/aFVdnfN0_HI ) i'm able to set the DISPLAY variable for each chrome instance now to control on which display the instance should be started.

Just use one of the following methods to set the display environment variable:

ChromeDriverService chromeDriverService = new ChromeDriverService.Builder()
                            .usingDriverExecutable(new File(ChromeUtils.getChromeDriverPath()))
                            .usingAnyFreePort()
                            .withEnvironment(ImmutableMap.of("DISPLAY",":1024"))
                            .build();

                    try {
                        chromeDriverService.start();
                        webDriver = new ChromeDriver(chromeDriverService, caps);
                    } ....

or use a simple argument for chromeOptions:

args.add("--display=:1024");
chromeOptions.addArguments(args);
whitenexx
  • 1,350
  • 2
  • 25
  • 53