Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (62.9k points)

So I'm trying some stuff out with selenium and I really want it to be quick.

So my thought is that running it with headless chrome would make my script faster.

First question is that Is it the correct assumption, or it does not matter if I run my script with a headless driver or not?

Anyway I still want to get it to work to run headless, but I somehow can't, I tried different things.

But when I try that, I get weird console output and it still doesn't seem to work.

Any tips appreciated.

1 Answer

0 votes
by (19.7k points)

To run chrome-headless just add --headless via chrome_options.add_argument, i.e.:

from selenium import webdriver

from selenium.webdriver.chrome.options import Options

chrome_options = Options()

#chrome_options.add_argument("--disable-extensions")

#chrome_options.add_argument("--disable-gpu")

chrome_options.add_argument("--headless")

driver = webdriver.Chrome(options=chrome_options)

start_url = "https://google.com"

driver.get(start_url)

print(driver.page_source.encode("utf-8"))

driver.quit()

# b'<!DOCTYPE html><html xmlns="http://www....

So my thought is that running it with headless chrome would make my script faster.

Try using chrome options like --disable-extensions or --disable-gpu and benchmark it, but I wouldn't count with much improvement.

References: headless-chrome

Note: As of today, when running chrome headless, you should include the  --disable-gpu flag if you're running on Windows.

If you are interested to learn Selenium on a much deeper level and want to become a professional in the testing domain, check out Intellipaat’s Selenium training!

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...