A headless browser is a web browser without a user interface, it means the browser is running in the background (invisbile). This is great if you want to start a web browser to do tasks, but you don’t want or need to see it.
You can use any Web Browser like Firefox or Chrome in a headless mode. To do so, first open up the Web Browser using the Web Driver and then set it to headless mode. In any case, the web driver needs to be installed.
Related course:
selenium
selenium firefox headless
Before you start, make sure the Web Browser, the Web Driver and the selenium module are all installed and working.
The code below starts Firefox, but in headless mode. It can do anything Firefox can, but it wont be visible on the screen. The screenshot below outputs the html code of the web page, but that’s optional.
1 | from selenium import webdriver |
It’s set as headless browser here, where FirefoxOptions() is used to make it headless.
1 | fireFoxOptions = webdriver.FirefoxOptions() |
After loading the headless web browser, you can proceed to using it as you would normally do with selenium. The only difference is that it’s not visible to the user.
If you are new to selenium, then I highly recommend this book.