top of page
back.jpg

Run Browser in Headless mode

Provide a Selenium script demonstrating how to run a browser in headless mode, specifically using Chrome

# Import necessary libraries
from selenium import webdriver
from selenium.webdriver.chrome.service import Service

# Create ChromeOptions and add the "headless" argument to run Chrome in headless mode
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("headless")

# Create a Service object for the Chrome browser
service_obj = Service()

# Initialize the Chrome WebDriver with the created Service and options
driver = webdriver.Chrome(service=service_obj, options=chrome_options)

# Open the specified website
driver.get("https://www.saucedemo.com")

# Set an implicit wait of 3 seconds to allow elements to be found
driver.implicitly_wait(3)

# Maximize the browser window
driver.maximize_window()

# Print the title of the current webpage to the console
print(driver.title)

# Close the browser window
driver.quit()

8 views0 comments

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page