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

What is Flaky test? Steps to resolve Test Flakiness

A flaky test An automated test in a software testing environment that may produce inconsistent results, sometimes passing and sometimes failing, even when applied to the same version of the software u

Retrieve data from a JSON file

To retrieve data from a JSON file using Java and Selenium, you can use a library like Gson or Jackson for handling JSON parsing. { "username": "Tester1", "password": "Test1234", "url": "https://demoqa

bottom of page