Search This Blog

Friday, February 4, 2022

Execute Selenium in Jupyter Notebook - Headless Mode

In the previous example, when you run the script, you will be able to see the chrome browser getting activated and follows the command in the script. 

Headless mode runs the code without the need of the physical browser. It executes the same script behind the scenes, without opening the browser window at all. 

This makes automation much easier and efficient in a way. Speed and performance is amazing in this scenario. You can run multiple tests in parallel without the overhead of multiple browsers being open all through the execution time frame. 

Below is what how you can run the code from the previous post in the headless mode. 

from time import sleep
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from import By
from import Options
options = Options()
options.headless = True
driver = webdriver.Chrome(options=options)

driver.find_element("name", "q").send_keys("Elon Musk")

Result will be the same, but no browsers are opened. 

No comments:

Post a Comment