Trigger Headless Test Execution in Selenium with Python



Selenium supports headless execution. In the Chrome browser, the headless execution can be implemented with the help of the ChromeOptions class. We have to create an object of this class and apply the add_arguments method to it. Finally, pass the parameter --headless to this method.

Let us obtain the title - About Careers at Tutorials Point - Tutorialspoint of the page launched in a headless mode −

Example

Code Implementation

from selenium import webdriver from selenium.webdriver.chrome.options import Options #object of Options class c = Options() #passing headless parameter c.add_argument("--headless") #adding headless parameter to webdriver object driver = webdriver.Chrome(executable_path='../drivers/chromedriver', options=c) # implicit wait time driver.implicitly_wait(5) # url launch driver.get("https://www.tutorialspoint.com/about/about_careers.htm") print('Page title: ' + driver.title) # driver quit driver.quit()

Output

Updated on: 2021-11-19T10:58:05+05:30

903 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements