BrowserOptions Breakdown for SDETs using Selenium WebDriver

Japneet Sachdeva
2 min readJul 11, 2024

--

Img src: StackOverFlow

BrowserOptions BreakDown for Selenium WebDriver 4.0 & Greater

  1. Handling AdBlocker: Stops the browser to load ads when adblocker is enabled!
// Set up ChromeOptions to add the extension and exclude the disable-popup-blocking switch
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("Path to CRX File")); // Replace with the path to your CRX file
options.setExperimentalOption("excludeSwitches", List.of("disable-popup-blocking"));
WebDriver driver = new ChromeDriver(options);

Use this app, to extract CRX for your adblocker: https://crxextractor.com/

2. Using Incognito Mode: Used in cases where you do not want to use existing credentials, cookies, cache etc.

// Set up ChromeOptions to enable incognito mode
ChromeOptions options = new ChromeOptions();
options.addArguments(" - incognito");
WebDriver driver = new ChromeDriver(options);

3. Keeping browser open (detached mode): Used when you want to keep the browser in open state even after the WebDriver session is ended

// Set up ChromeOptions to enable the detach option
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("detach", true);
WebDriver driver = new ChromeDriver(options);

Note: As per Selenium Docs, this behavior is default for Java but it does not work for me!

4. Keep pop-up blocker active

// Set up ChromeOptions to enable the disable extensions option
ChromeOptions options = new ChromeOptions();
options.addArguments(" - disable-extensions");
WebDriver driver = new ChromeDriver(options);

You can read more about it here: https://shorturl.at/C5LGe

5. Store Browser Logs in an existing or new file

// Create a ChromeDriverService with the specified log file location
ChromeDriverService service = new ChromeDriverService.Builder()
.withLogFile(logLocation)
.build();
ChromeOptions options = new ChromeOptions();
options.addArguments(" - start-maximized");
WebDriver driver = new ChromeDriver(service, options);

6. Headless mode: Browser UI not visible and tests are executing in non GUI mode

ChromeOptions options = new ChromeOptions();
options.addArguments(" - headless");
WebDriver driver = new ChromeDriver(options);

7. Disabling developer extension pop-up

ChromeOptions options = new ChromeOptions();
options.addArguments(" - disable-extensions");
WebDriver driver = new ChromeDriver(options);

8. Disable InfoBars: Prevents Chrome from displaying the notification ‘Chrome is being controlled by automated software

ChromeOptions options = new ChromeOptions();
options.addArguments(" - disable-infobars");
WebDriver driver = new ChromeDriver(options);

-x-x-

Get your next SDET job, using my latest 2024 Interview Questions & Answer Bank: Link

Framework creation for SDETs is a crucial skill expected in interviews and jobs, if you lack such skill then take my new course: Link

Follow me on LinkedIn: https://www.linkedin.com/in/japneet-sachdeva

Subscribe to my YouTube Channel: https://www.youtube.com/@IamJapneetSachdeva

#japneetsachdeva

--

--