Answer the question
In order to leave comments, you need to log in
How to launch web driver chrome without opening a browser window (i.e. in the background)?
Hey!
When writing the parser, I used Selenium with webbriver Chrome. Everything works fine, but at startup it opens a browser window. The code is the following:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from datetime import datetime, timedelta
from pyvirtualdisplay import Display
from selenium.webdriver.chrome.options import Options
browser = webdriver.Chrome(chrome_options=chrome_options)
browser.get('https://www.itau.com.br')
display = Display(visible=0, size=(800, 600))
display.start()
chrome_options = Options()
chrome_options.add_argument("--no-startup-window")
browser = webdriver.Chrome(chrome_options=chrome_options)
File "/Users/Lutchenko/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/Users/Lutchenko/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Users/Lutchenko/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/Users/Lutchenko/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "/Users/Lutchenko/Library/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: unable to discover open pages
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Mac OS X 10.12.2 x86_64)
Answer the question
In order to leave comments, you need to log in
In general, having rummaged fairly on the Internet, I realized that, for now, it is impossible to run Chrome with Selenium in headless mode (that is, in the background) on Mac OS , but soon such an opportunity will appear. Same story with Firefox. I put Ubuntu for tests.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question