1

I have following code:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument('--headless')
options.add_argument('--disable-gpu')
driver = webdriver.Chrome("chromedriver.exe", chrome_options=options)

driver.get("*some site*")

When i start debugging, it stucks at the driver.get("*some site*") line. It simply does not start anything. Any suggestions please? Everything is up to date. Using windows 7. EDIT: using Python 3.6

EDIT 2: hope its helpful

Jan Šuman
  • 61
  • 1
  • 4
  • I believe it always needs a display. You should take a look at `virtual displays` since you are in a headless environment. (https://stackoverflow.com/questions/6183276/how-do-i-run-selenium-in-xvfb) – Chuk Ultima Feb 10 '18 at 16:44
  • well, i used to use PhantomJS, but since it had some problems with locating elements, i tried using this. Anyway thx for suggestion. – Jan Šuman Feb 10 '18 at 16:46
  • I have looked on those virtual displays and it looks like i cant use them on windows machine, or am i wrong? – Jan Šuman Feb 10 '18 at 17:12
  • Update the question with the version info of the binaries you are using along with the error stack trace for further analysis. – undetected Selenium Feb 10 '18 at 18:34
  • thanks for you reply, however, how to provide these informations please? I mean, where do I find them. Kinda new to python, thanks for understanding. – Jan Šuman Feb 10 '18 at 22:17

1 Answers1

1

try running with this options, for me (on my win machine) --no-sandbox helped. --log-path and verbose obviously helps with debugging.

ch_options.add_argument('--headless')
ch_options.add_argument('--disable-gpu')
ch_options.add_argument('--no-sandbox')
ch_options.add_argument('--log-path=chromedriver.log')
ch_options.add_argument('--verbose')

and for user agent (in case some websites protest):

ch_options.add_argument(
    '--user-agent="valid user agent :)"')

and starting it:

driver = webdriver.Chrome(chrome_options=ch_options)

my chromedriver is in PATH environmental variable so no need to pass executable in here.

btw. phantomjs driver is not updated any more so try to resolve this and switch to chromedriver. I.e. for me the phantomjs driver wont even let me change user-agent, just on python binding though.

Tom St
  • 908
  • 8
  • 15
  • 1
    Does not work for me. Still looks like it stucks on driver.get("****") line. – Jan Šuman Feb 10 '18 at 17:07
  • post the outpout of running it with --verbose or just paste the content of logs, it should has some details. – Tom St Feb 10 '18 at 17:10
  • It does not output any errors/exceptions. Where do I find that log please? It just looks like it freezes on that driver.get. After 10 minutes of work it said something like "request timeout". – Jan Šuman Feb 10 '18 at 17:16
  • I used the following code you have suggested, nothing changed. – Jan Šuman Feb 10 '18 at 17:20
  • If you will run it with this option --log-path=chromedriver.log it should log it in directory in which you're running script so if its C:\folder\script.py and you run it from that directory, you can as well use full path. – Tom St Feb 10 '18 at 18:47
  • 1
    and does it work when running in standard (non-headless) mode so starting up chrome and getting to webpage etc.? – Tom St Feb 10 '18 at 18:47
  • yeah, in normal mode (headed or how to call it) it just runs fine. – Jan Šuman Feb 10 '18 at 22:14