Amruta
Amruta

Reputation: 1166

URL is not opening in headless chrome using Selenium java and windows os

I am facing below issue while running scripts on chrome headless using Selenium java and in Windows OS. URL is not opening i am getting null as a title of page for my application URL..chrome driver version 2.33 ,chrome browser 62..I am using below code

System.setProperty("webdriver.chrome.driver", chromedriver.exe);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
chromeOptions.addArguments("window-sized1200,600");
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("app url");
System.out.println(driver.getTitle)

Is it because by app URL is not supported headless mode ..not getting any exception..

Upvotes: 3

Views: 4836

Answers (2)

undetected Selenium
undetected Selenium

Reputation: 193078

You have to consider a couple of changes as follows :

  • While you do System.setProperty provide the absolute path of the chromedriver binary.

    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
    
  • The argument for window-size is options.addArguments("window-size=1400,600");

    chromeOptions.addArguments("window-size=1400,600");
    
  • While you do driver.get() include the https and www

    driver.get("https://www.google.co.in");
    
  • To retrive the Page Title the method is getTitle()

    System.out.println(driver.getTitle());
    
  • Your modified code block will look like :

    System.setProperty("webdriver.chrome.driver", "C:\\path\\to\\chromedriver.exe");
    ChromeOptions chromeOptions = new ChromeOptions();
    chromeOptions.addArguments("--headless");
    chromeOptions.addArguments("window-size=1400,600");
    WebDriver driver =  new ChromeDriver(chromeOptions);
    driver.get("https://www.google.co.in");
    System.out.println(driver.getTitle());
    

Upvotes: 0

Marcel
Marcel

Reputation: 1463

There is a typo in your window size argument and you call addArguments but you only add one argument per call, try this

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("headless", "window-size=1200,600");
ChromeDriver driver = new ChromeDriver(chromeOptions);
driver.get("your.app.url");
System.out.println(driver.getTitle)

Upvotes: 1

Related Questions