top of page
back.jpg

Run Browser in Headless mode

crystgandhi

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()

9 views0 comments

Recent Posts

See All

Test case for Valid Coupon Code

This test case checks whether a valid coupon code is successfully applied to a booking cart, the total is updated accordingly, and a...

Keyboard shortcut keys for various operations

General Shortcuts: Ctrl + C: Copy Ctrl + X: Cut Ctrl + V: Paste Ctrl + Z: Undo Ctrl + Y: Redo Ctrl + A: Select All Ctrl + S: Save Ctrl +...

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page