-1

I’m able to load a webpage using a headed chrome driver but when trying to load the same page with headless chrome driver, the driver becomes stuck loading.

I’ve set the header agent to be the same on both, but it’s still not able to connect to the page.

Any suggestions?

I was thinking if there’s a method like

driver.capabilities[“headless”]=False

Or something like that?

Reproducible code:

user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36'
chrome_path="/Users/"+pwd.getpwuid(os.getuid())[0]+"/Desktop/chromedriver"

# headless driver
chrome_options=Options()
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("headless")
chrome_options.add_argument('user-agent={'+user_agent+'}')
driver1=webdriver.Chrome(executable_path=chrome_path, chrome_options=chrome_options)
driver1.set_page_load_timeout(10)
driver1.get("http://www.adidas.com/")

Output:

TimeoutException: Message: timeout
  (Session info: headless chrome=62.0.3202.94)
  (Driver info: chromedriver=2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2),platform=Mac OS X 10.13.1 x86_64)
Brandon
  • 50
  • 7
  • What version of chrome driver are you using? – Mangohero1 Nov 20 '17 at 15:51
  • I am using version 62.0.3202.94 – Brandon Nov 20 '17 at 16:09
  • Yes, I did `chrome_options.add_argument("headless")` and it makes a headless browser. It's able to connect to some pages but certain pages it cannot reach. While a headed driver is able to connect to all the pages I've tested. – Brandon Nov 20 '17 at 16:15

1 Answers1

0

The add_argument is not "headless", instead it's "--headless"

So our code will be :

chrome_options=Options()
chrome_options.add_argument("disable-infobars")
chrome_options.add_argument("--headless")
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352