2

I am using maven here.Here is my Selenium code:

DesiredCapabilities capb = DesiredCapabilities.chrome(); capb.setCapability("chrome.binary","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"); ChromeOptions options = new ChromeOptions(); options.addArguments("--headless","--disable-gpu", "--no-sandbox","--remote-debugging-port=9222"); capb.setCapability(ChromeOptions.CAPABILITY, options); System.setProperty("webdriver.chrome.driver","/Users/nitinkumar/TEST/chromedriver"); try{ ChromeDriver driver = new ChromeDriver(capb); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://qa.cmnetwork.co"); driver.quit(); } catch(Exception e) { e.printStackTrace(); } 

when I run "mvn test" it starts the chrome in GUI mode. but It should open in Headless mode. I have chrome vesrion 59.0, OS X yosemite(10.10.5), chromedriver 2.30 and Selenium 3.4.0.

4
  • It's worth to mention Headless mode is available on Mac and Linux in Chrome 59. Windows support is coming in Chrome 60. To check what version of Chrome you have, open chrome://version. Commented Jun 27, 2017 at 10:42
  • I have already mentioned in my question. I made it bold now. Commented Jun 27, 2017 at 10:47
  • how about setting option like driver = new ChromeDriver(options); Commented Jun 27, 2017 at 10:49
  • tried but still open in GUI mode not in headless mode. Commented Jun 27, 2017 at 10:52

1 Answer 1

3

It won't open in GUI mode. Just the chrome launcher icon will be opened. And it is an expected behaviour.

You have to remove the argument --remote-debugging-port. That will block the launched headless Chrome. So the script will never move forward.And you will get a chrome not reachable error

So change the arguments like

options.addArguments("--headless","--disable-gpu", "--no-sandbox"); 

Also, there is no need for --no-sandbox. As per Official doc only --headless and --disable-gpu flags are enough

Unless you have multiple versions of chrome installed, there is no need for DesiredCapabilities as well.

So the simple code for headless-chrome

 ChromeOptions options = new ChromeOptions(); options.addArguments("--headless","--disable-gpu"); System.setProperty("webdriver.chrome.driver","/Users/nitinkumar/TEST/chromedriver"); ChromeDriver driver = new ChromeDriver(options); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); driver.get("https://qa.cmnetwork.co"); driver.quit(); 
Sign up to request clarification or add additional context in comments.

1 Comment

I would suggest just to keep --no-sandbox. Keeping --disable-gpu argument doesn't show chrome UI via selenium in Linux (in my little experience).

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.