Bird
Raised Fist0
Selenium Javatesting~20 mins

ChromeOptions configuration in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
ChromeOptions Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate
2:00remaining
What is the output of this ChromeOptions configuration code?
Consider the following Java Selenium code snippet configuring ChromeOptions. What will be the value of options.toString() after execution?
Selenium Java
import org.openqa.selenium.chrome.ChromeOptions;

public class Test {
    public static void main(String[] args) {
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--headless");
        options.addArguments("--disable-gpu");
        System.out.println(options.toString());
    }
}
AChromeOptions: {args=[]}
BChromeOptions: {args=[--headless, --disable-gpu]}
CChromeOptions: {args=[--disable-gpu, --headless]}
DChromeOptions: {args=[--headless]}
Attempts:
2 left
💡 Hint
The order of addArguments calls is preserved in the args list.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies that ChromeOptions has the 'incognito' argument?
Given a ChromeOptions object options with arguments added, which assertion correctly checks that '--incognito' is present in the arguments list?
Selenium Java
import org.openqa.selenium.chrome.ChromeOptions;
import static org.junit.jupiter.api.Assertions.assertTrue;

ChromeOptions options = new ChromeOptions();
options.addArguments("--incognito");
AassertTrue(options.getArguments().contains("--incognito"));
BassertTrue(options.toString().equals("--incognito"));
CassertTrue(options.getArguments().equals("--incognito"));
DassertTrue(options.getArguments().indexOf("incognito") > 0);
Attempts:
2 left
💡 Hint
Check the type returned by getArguments() and how to verify presence of an element.
🔧 Debug
advanced
2:00remaining
Why does this ChromeOptions code cause a runtime error?
Examine the following code snippet. Why does it throw a NullPointerException at runtime?
Selenium Java
ChromeOptions options = null;
options.addArguments("--start-maximized");
ABecause options is null and calling addArguments on null causes NullPointerException.
BBecause addArguments does not accept string arguments.
CBecause --start-maximized is not a valid Chrome argument.
DBecause ChromeOptions must be initialized with a WebDriver instance.
Attempts:
2 left
💡 Hint
Check the initialization of the options variable before method call.
❓ framework
advanced
2:00remaining
Which ChromeOptions configuration disables extensions and runs in headless mode?
Select the correct Java Selenium ChromeOptions code snippet that disables browser extensions and runs Chrome in headless mode.
A
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
options.setHeadless(false);
B
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions", "--headless");
C
ChromeOptions options = new ChromeOptions();
options.addArguments("headless", "disable-extensions");
D
ChromeOptions options = new ChromeOptions();
options.setHeadless(true);
options.addArguments("--disable-extensions");
Attempts:
2 left
💡 Hint
Use the setHeadless method to enable headless mode properly.
🧠 Conceptual
expert
2:00remaining
What is the effect of adding '--remote-debugging-port=9222' in ChromeOptions?
In Selenium ChromeOptions, what does adding the argument '--remote-debugging-port=9222' do?
AIt sets the ChromeDriver to listen on port 9222 for WebDriver commands.
BIt disables all network connections except on port 9222.
CIt enables remote debugging on port 9222, allowing external tools to connect to Chrome for debugging.
DIt forces Chrome to use port 9222 for all HTTP requests.
Attempts:
2 left
💡 Hint
Think about what remote debugging means in browser context.

Practice

(1/5)
1. What is the primary purpose of using ChromeOptions in Selenium Java?
easy
A. To locate elements on a web page
B. To write test assertions for Chrome browser
C. To customize Chrome browser settings before launching it
D. To manage test data inputs

Solution

  1. Step 1: Understand ChromeOptions role

    ChromeOptions is used to set browser preferences like headless mode or window size before starting Chrome.
  2. Step 2: Differentiate from other Selenium tasks

    It is not used for assertions, locating elements, or managing test data, which are separate concerns.
  3. Final Answer:

    To customize Chrome browser settings before launching it -> Option C
  4. Quick Check:

    ChromeOptions = browser customization [OK]
Hint: ChromeOptions sets browser behavior before launch [OK]
Common Mistakes:
  • Confusing ChromeOptions with element locators
  • Thinking ChromeOptions handles test assertions
  • Assuming ChromeOptions manages test data
2. Which of the following is the correct way to add the argument to start Chrome maximized using ChromeOptions in Java?
easy
A. options.addArguments("--start-maximized");
B. options.addArgument("start-maximized");
C. options.setArguments("--start-maximized");
D. options.addArguments("startMaximized");

Solution

  1. Step 1: Recall correct method name

    The method to add arguments is addArguments (plural), not addArgument or setArguments.
  2. Step 2: Use correct argument format

    Arguments must start with double dashes, so "--start-maximized" is correct.
  3. Final Answer:

    options.addArguments("--start-maximized"); -> Option A
  4. Quick Check:

    Method = addArguments, Argument = "--start-maximized" [OK]
Hint: Use addArguments("--option") with double dashes [OK]
Common Mistakes:
  • Using singular addArgument instead of addArguments
  • Omitting double dashes in argument string
  • Using incorrect method setArguments
3. Given the following code snippet, what will be the effect when launching Chrome?
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--disable-gpu");
ChromeDriver driver = new ChromeDriver(options);
medium
A. Chrome will launch in normal mode with GPU enabled
B. Chrome will launch maximized but not headless
C. Chrome will throw a syntax error due to addArguments usage
D. Chrome will launch in headless mode with GPU disabled

Solution

  1. Step 1: Analyze added arguments

    The arguments "--headless" and "--disable-gpu" tell Chrome to run without UI and disable GPU acceleration.
  2. Step 2: Understand ChromeDriver initialization

    Passing options to ChromeDriver applies these settings, so Chrome runs headless with GPU disabled.
  3. Final Answer:

    Chrome will launch in headless mode with GPU disabled -> Option D
  4. Quick Check:

    Arguments = headless + disable GPU [OK]
Hint: Headless mode needs "--headless" argument [OK]
Common Mistakes:
  • Thinking addArguments causes syntax error
  • Assuming headless mode still shows UI
  • Ignoring GPU disable argument effect
4. Identify the error in the following code snippet that configures ChromeOptions:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
ChromeDriver driver = new ChromeDriver(options);
medium
A. Missing double dashes before argument "start-maximized"
B. Incorrect method name; should be addArgument instead of addArguments
C. ChromeOptions cannot be passed to ChromeDriver constructor
D. No error; code is correct

Solution

  1. Step 1: Check argument format

    The argument "start-maximized" lacks the required "--" prefix for Chrome options.
  2. Step 2: Verify method and usage

    The method addArguments is correct and ChromeOptions can be passed to ChromeDriver constructor, so no error there.
  3. Final Answer:

    Missing double dashes before argument "start-maximized" -> Option A
  4. Quick Check:

    Arguments need "--" prefix [OK]
Hint: Chrome arguments always start with "--" [OK]
Common Mistakes:
  • Omitting double dashes in argument strings
  • Confusing addArguments with addArgument
  • Thinking ChromeOptions can't be passed to ChromeDriver
5. You want to launch Chrome in headless mode, disable extensions, and start maximized using ChromeOptions. Which code snippet correctly applies all these settings?
hard
A. ChromeOptions options = new ChromeOptions(); options.addArgument("--headless", "--disable-extensions", "--start-maximized"); ChromeDriver driver = new ChromeDriver(options);
B. ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); options.addArguments("--disable-extensions"); options.addArguments("--start-maximized"); ChromeDriver driver = new ChromeDriver(options);
C. ChromeOptions options = new ChromeOptions(); options.addArguments("headless"); options.addArguments("disable-extensions"); options.addArguments("start-maximized"); ChromeDriver driver = new ChromeDriver(options);
D. ChromeOptions options = new ChromeOptions(); options.setArguments(List.of("--headless", "--disable-extensions", "--start-maximized")); ChromeDriver driver = new ChromeDriver(options);

Solution

  1. Step 1: Identify required arguments

    The settings require "--headless", "--disable-extensions", and "--start-maximized", all prefixed with "--".
  2. Step 2: Confirm correct method

    Use addArguments() (plural); invalid methods like addArgument() or setArguments() cause errors.
  3. Step 3: Validate implementation

    Correct code applies each argument via separate addArguments calls.
  4. Final Answer:

    ChromeOptions options = new ChromeOptions(); options.addArguments("--headless"); options.addArguments("--disable-extensions"); options.addArguments("--start-maximized"); ChromeDriver driver = new ChromeDriver(options); -> Option B
  5. Quick Check:

    addArguments("--headless"), addArguments("--disable-extensions"), addArguments("--start-maximized") [OK]
Hint: Call addArguments separately with "--" prefixed options [OK]
Common Mistakes:
  • Passing arguments without "--" prefix
  • Using addArgument instead of addArguments
  • Using non-existent setArguments method
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard