Bird
Raised Fist0
Selenium Javatesting~20 mins

FirefoxOptions configuration in Selenium Java - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
FirefoxOptions 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 FirefoxOptions configuration code?
Consider the following Java Selenium code snippet configuring FirefoxOptions. What will be the value of the 'headless' option after execution?
Selenium Java
import org.openqa.selenium.firefox.FirefoxOptions;

public class Test {
    public static void main(String[] args) {
        FirefoxOptions options = new FirefoxOptions();
        options.setHeadless(true);
        options.addArguments("-private");
        System.out.println(options.isHeadless());
    }
}
Atrue
Bfalse
Cnull
DCompilation error
Attempts:
2 left
💡 Hint
Check the method used to set headless mode and the method to retrieve it.
❓ assertion
intermediate
2:00remaining
Which assertion correctly verifies FirefoxOptions has the argument '-private'?
Given a FirefoxOptions object configured with addArguments("-private"), which assertion correctly checks this argument is present?
Selenium Java
FirefoxOptions options = new FirefoxOptions();
options.addArguments("-private");
AassertNull(options.getProfile().getArguments());
BassertEquals(options.getProfile().getArguments(), "-private");
CassertFalse(options.getProfile().getArguments().isEmpty());
DassertTrue(options.getProfile().getArguments().contains("-private"));
Attempts:
2 left
💡 Hint
Check how to verify a list contains a specific string.
❓ locator
advanced
2:00remaining
Identify the best way to locate the Firefox binary path in FirefoxOptions
Which code snippet correctly sets the Firefox binary path to '/usr/bin/firefox' in FirefoxOptions?
Aoptions.setBinary("/usr/bin/firefox");
Boptions.setBinary(new File("/usr/bin/firefox"));
Coptions.setBinary(new FirefoxBinary(new File("/usr/bin/firefox")));
Doptions.setBinary("firefox", "/usr/bin/firefox");
Attempts:
2 left
💡 Hint
Check the expected parameter type for setBinary method.
🔧 Debug
advanced
2:00remaining
Why does this FirefoxOptions code cause a compilation error?
Identify the error in the following code snippet:
Selenium Java
FirefoxOptions options = new FirefoxOptions();
options.addArguments(-private);
AThe code is correct and compiles without error.
BMissing quotes around '-private' causes a compilation error.
CCannot assign FirefoxOptions to options variable without import.
DaddArguments method does not exist in FirefoxOptions.
Attempts:
2 left
💡 Hint
Check the argument type passed to addArguments.
❓ framework
expert
3:00remaining
Which FirefoxOptions configuration will correctly enable headless mode and disable GPU acceleration for a Selenium test?
Select the code snippet that correctly configures FirefoxOptions to run headless and disable GPU acceleration.
A
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
options.addArguments("--disable-gpu");
B
FirefoxOptions options = new FirefoxOptions();
options.addArguments("--headless", "--disable-gpu");
C
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(false);
options.addArguments("--disable-gpu");
D
FirefoxOptions options = new FirefoxOptions();
options.setHeadless(true);
options.addArguments("-disable-gpu");
Attempts:
2 left
💡 Hint
Check the correct method to enable headless mode and the correct argument syntax for disabling GPU.

Practice

(1/5)
1. What is the primary purpose of using FirefoxOptions in Selenium Java?
easy
A. To customize Firefox browser settings before launching it
B. To write test assertions for Firefox browser
C. To locate elements on a Firefox webpage
D. To generate test reports for Firefox tests

Solution

  1. Step 1: Understand FirefoxOptions role

    FirefoxOptions is used to set browser preferences, add arguments, or configure profiles before starting Firefox.
  2. Step 2: Differentiate from other Selenium tasks

    Locating elements, assertions, and reports are separate tasks not handled by FirefoxOptions.
  3. Final Answer:

    To customize Firefox browser settings before launching it -> Option A
  4. Quick Check:

    FirefoxOptions = browser customization [OK]
Hint: FirefoxOptions sets browser behavior before launch [OK]
Common Mistakes:
  • Confusing FirefoxOptions with element locators
  • Thinking FirefoxOptions handles test assertions
  • Assuming FirefoxOptions generates reports
2. Which of the following is the correct way to create a FirefoxOptions object and add the argument --headless in Java?
easy
A. FirefoxOptions options = new FirefoxOptions(); options.setHeadless(true);
B. FirefoxOptions options = new FirefoxOptions(); options.addArguments("--headless");
C. FirefoxOptions options = new FirefoxOptions(); options.addArgument("headless");
D. FirefoxOptions options = new FirefoxOptions(); options.setArguments("--headless");

Solution

  1. Step 1: Check method names for adding arguments

    The correct method to add command line arguments is addArguments(String... args).
  2. Step 2: Verify argument syntax and method usage

    FirefoxOptions options = new FirefoxOptions(); options.addArguments("--headless"); uses addArguments("--headless") which is correct. FirefoxOptions options = new FirefoxOptions(); options.setHeadless(true); uses a non-existent method setHeadless. Options C and D use incorrect method names or argument formats.
  3. Final Answer:

    FirefoxOptions options = new FirefoxOptions(); options.addArguments("--headless"); -> Option B
  4. Quick Check:

    Use addArguments("--headless") to set headless mode [OK]
Hint: Use addArguments("--headless") to enable headless mode [OK]
Common Mistakes:
  • Using incorrect method names like setHeadless or setArguments
  • Missing double dashes in argument string
  • Using singular addArgument instead of addArguments
3. What will be the effect of the following Java code snippet using FirefoxOptions?
FirefoxOptions options = new FirefoxOptions();
options.setAcceptInsecureCerts(true);
FirefoxDriver driver = new FirefoxDriver(options);
driver.get("https://expired.badssl.com/");
medium
A. The browser will open but block the page due to certificate error
B. The browser will throw an exception due to insecure certificate
C. The browser will open the URL and ignore the insecure SSL certificate warning
D. The code will not compile because setAcceptInsecureCerts is invalid

Solution

  1. Step 1: Understand setAcceptInsecureCerts(true)

    This setting tells Firefox to accept insecure SSL certificates without blocking or warning.
  2. Step 2: Analyze code behavior on expired.badssl.com

    Since the site has an expired certificate, normally Firefox blocks it. But with this option true, it will load the page ignoring the warning.
  3. Final Answer:

    The browser will open the URL and ignore the insecure SSL certificate warning -> Option C
  4. Quick Check:

    setAcceptInsecureCerts(true) = ignore SSL warnings [OK]
Hint: setAcceptInsecureCerts(true) bypasses SSL errors [OK]
Common Mistakes:
  • Assuming insecure certs cause exceptions
  • Thinking the browser blocks page despite option
  • Confusing compile errors with runtime behavior
4. Identify the error in this code snippet that tries to set a Firefox profile using FirefoxOptions:
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.startup.homepage", "https://example.com");
FirefoxOptions options = new FirefoxOptions();
options.setProfile(profile);
FirefoxDriver driver = new FirefoxDriver();
medium
A. FirefoxDriver constructor requires a WebDriverWait parameter
B. FirefoxProfile cannot be set using setPreference method
C. FirefoxOptions does not support setProfile method
D. FirefoxDriver is created without passing FirefoxOptions, so profile is ignored

Solution

  1. Step 1: Check FirefoxDriver constructor usage

    The driver is created with new FirefoxDriver() without passing the configured options.
  2. Step 2: Understand consequence of missing options

    Without passing options, the profile settings are ignored and default Firefox starts.
  3. Final Answer:

    FirefoxDriver is created without passing FirefoxOptions, so profile is ignored -> Option D
  4. Quick Check:

    Pass options to FirefoxDriver to apply profile [OK]
Hint: Always pass FirefoxOptions to FirefoxDriver constructor [OK]
Common Mistakes:
  • Forgetting to pass options to FirefoxDriver
  • Thinking setPreference is invalid
  • Assuming FirefoxDriver needs WebDriverWait in constructor
5. You want to run Firefox in headless mode with a custom profile that disables images to speed up tests. Which code snippet correctly configures FirefoxOptions for this scenario?
hard
A. FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("permissions.default.image", 2); FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); options.addArguments("--headless"); FirefoxDriver driver = new FirefoxDriver(options);
B. FirefoxOptions options = new FirefoxOptions(); options.addArguments("headless"); options.setPreference("permissions.default.image", 2); FirefoxDriver driver = new FirefoxDriver(options);
C. FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("permissions.default.image", false); FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); options.addArguments("--headless"); FirefoxDriver driver = new FirefoxDriver();
D. FirefoxOptions options = new FirefoxOptions(); options.setProfile("permissions.default.image", 2); options.addArguments("--headless"); FirefoxDriver driver = new FirefoxDriver(options);

Solution

  1. Step 1: Disable images using FirefoxProfile preference

    The correct preference to disable images is permissions.default.image set to 2.
  2. Step 2: Set profile and add headless argument in FirefoxOptions

    Create FirefoxOptions, set the profile, add "--headless" argument, then pass options to FirefoxDriver constructor.
  3. Step 3: Verify correct method usage and constructor call

    FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("permissions.default.image", 2); FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); options.addArguments("--headless"); FirefoxDriver driver = new FirefoxDriver(options); correctly does all steps. FirefoxOptions options = new FirefoxOptions(); options.addArguments("headless"); options.setPreference("permissions.default.image", 2); FirefoxDriver driver = new FirefoxDriver(options); tries to set preference directly on options (invalid). FirefoxProfile profile = new FirefoxProfile(); profile.setPreference("permissions.default.image", false); FirefoxOptions options = new FirefoxOptions(); options.setProfile(profile); options.addArguments("--headless"); FirefoxDriver driver = new FirefoxDriver(); uses false instead of 2 and misses passing options to driver. FirefoxOptions options = new FirefoxOptions(); options.setProfile("permissions.default.image", 2); options.addArguments("--headless"); FirefoxDriver driver = new FirefoxDriver(options); uses setProfile incorrectly.
  4. Final Answer:

    Option A code snippet correctly configures FirefoxOptions for headless with image disabled -> Option A
  5. Quick Check:

    Use profile.setPreference and addArguments("--headless") [OK]
Hint: Set profile prefs then add headless argument before driver creation [OK]
Common Mistakes:
  • Setting preferences directly on FirefoxOptions
  • Passing wrong values to preferences
  • Not passing options to FirefoxDriver constructor
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