Python, PhantomJS says I am not using headless? Python, PhantomJS says I am not using headless? selenium selenium

Python, PhantomJS says I am not using headless?


Selenium considers PhantomJS as deprecated, so you need to us either Chrome or Firefox in headless mode.

Here are the steps to use Chrome in headless mode:

  1. download chrome driver from https://sites.google.com/a/chromium.org/chromedriver/getting-started
  2. extract it to a folder
  3. add this folder to your PATH environment variable (if you don't do it, you will have to use webdriver.Chrome('/your/path/to/chromedriver') in the code below instead of webdriver.Chrome())

Then use it like this:

from selenium import webdriver# prepare the option for the chrome driveroptions = webdriver.ChromeOptions()options.add_argument('headless')# start chrome browserbrowser = webdriver.Chrome(chrome_options=options)browser.get('http://www.google.com/xhtml')print(browser.current_url)browser.quit()

More on how to use ChromeDriver
For the other options: here (also here and here)


In Selenium 3.8.1 PhantomJS marked as deprecated webdriver and recommend us to use either Chrome or Firefox in headless mode.


You could use this:

from selenium import webdriverbrowser = webdriver.Chrome('chromedriver_path/chromedriver')browser.get("https://www.test.com")print(browser.current_url)browser.quit()