Fun with Learning Technology
LearnCoursesQuestionsTracksToolsNewsExplorePractice
Fun with Learning Technology

A new problem, explained clearly, every day.

Subscribe
Learn
  • Lessons
  • Topics
  • News
  • Tools
  • Courses
  • Career tracks
  • Everything
Site
  • About
  • Contact
  • Support
  • Privacy
  • Terms
Get the daily one

One email per new problem. No spam.

Request a tutorial

Requests shape what gets made next.

© 2026 Fun with Learning TechnologyRSS
Home›Selenium›Quiz

Selenium quiz

Ten questions at a time, drawn from 90. Every answer is explained. Nothing is saved and no account is needed.

Question 1 of 10Score 0

What is the primary function of the WebDriver server in the Selenium architecture?

Practice quiz for Selenium. Scores are not saved.

Study first?

Every question comes from a lesson in the Selenium course.

Read the course →

Interview prep

Written questions with full answers.

Selenium interview questions →

All Selenium quiz questions and answers

  1. What is the primary function of the WebDriver server in the Selenium architecture?

    • To compile the source code into bytecode
    • To interpret commands from the client and translate them into browser-specific instructions
    • To store all the test data and results in a centralized database
    • To bypass security layers of the web application under test

    Answer: To interpret commands from the client and translate them into browser-specific instructions. The server acts as a bridge between the automation script and the browser driver. Option 0 is wrong as that is the compiler's job. Option 2 is wrong as Selenium does not manage data storage. Option 3 is wrong as it is not a security tool.

    From lesson: Selenium Overview and Architecture

  2. Why does Selenium use a client-server architecture?

    • To allow the test code to run on a machine different from where the browser is launched
    • To force the browser to restart after every individual command
    • To ensure that the browser is always rendered in headless mode by default
    • To eliminate the need for any browser-specific drivers

    Answer: To allow the test code to run on a machine different from where the browser is launched. This architecture decouples the execution environment from the test logic. Option 1 is incorrect as browser restarts are inefficient. Option 2 is false as headless mode is optional. Option 3 is false as drivers are necessary for communication.

    From lesson: Selenium Overview and Architecture

  3. How does the W3C WebDriver standard impact current Selenium architecture?

    • It mandates that all tests must be written in a specific language
    • It provides a standardized set of commands that all browsers must support to ensure consistency
    • It removes the need for browsers to have their own driver executables
    • It restricts test execution to only local machines

    Answer: It provides a standardized set of commands that all browsers must support to ensure consistency. The standard ensures cross-browser compatibility by unifying command protocols. Option 0 is wrong as Selenium remains language-agnostic. Option 2 is false as drivers are required. Option 3 is false as remote execution remains supported.

    From lesson: Selenium Overview and Architecture

  4. What is the result of sending a command via the WebDriver API when the browser session has already been closed?

    • The command is queued until the browser is reopened
    • The command is ignored silently
    • A 'NoSuchSessionException' or similar error is returned to the client
    • The client automatically re-launches the browser instance

    Answer: A 'NoSuchSessionException' or similar error is returned to the client. The architecture requires an active session ID for valid communication. Option 0 is wrong as drivers do not queue commands for closed browsers. Option 1 is wrong as errors must be reported. Option 3 is wrong as self-healing is not a native architecture feature.

    From lesson: Selenium Overview and Architecture

  5. In the context of Selenium Grid, what is the role of the 'Node'?

    • To manage the distribution of test execution requests across the network
    • To provide a user-friendly interface for writing test scripts
    • To register itself with a hub and execute browser instances on demand
    • To act as a central repository for all test framework configurations

    Answer: To register itself with a hub and execute browser instances on demand. Nodes perform the actual automation work. Option 0 describes the Hub. Option 1 describes the IDE. Option 3 is wrong as the Hub manages configuration, not the Node.

    From lesson: Selenium Overview and Architecture

  6. What is the primary function of the WebDriver binary/executable in the browser automation architecture?

    • It translates Selenium commands into browser-specific instructions via a JSON-based protocol
    • It acts as a graphical interface to display the browser state to the user
    • It downloads the necessary updates for the browser automatically before the test starts
    • It replaces the need for the browser installation by emulating the engine

    Answer: It translates Selenium commands into browser-specific instructions via a JSON-based protocol. The driver acts as a bridge between your code and the browser engine. Option 1 describes the RESTful communication process correctly. Option 2 is wrong because the driver is a backend process. Option 3 is incorrect because the driver manages its own compatibility, not browser updates. Option 4 is false as a real browser must be installed.

    From lesson: Setting Up WebDriver — Chrome and Firefox

  7. Why is it recommended to use Selenium Manager over manual path configuration?

    • It makes the test execution significantly faster by skipping the driver load process
    • It automatically detects the installed browser version and downloads the compatible driver binary
    • It allows tests to run on multiple browsers without writing any browser-specific code
    • It enables the execution of tests on devices that do not have any browsers installed

    Answer: It automatically detects the installed browser version and downloads the compatible driver binary. Selenium Manager is designed to resolve environment setup issues by matching driver versions to browser versions. Option 1 is wrong because it adds a small initialization step. Option 3 is false as driver instantiation is still browser-specific. Option 4 is false because a browser is required for UI tests.

    From lesson: Setting Up WebDriver — Chrome and Firefox

  8. What occurs if you attempt to launch Chrome using a driver that is outdated for the current browser version?

    • The browser launches, but elements become unclickable
    • The script proceeds but executes commands much slower than usual
    • The session initialization fails, usually throwing a SessionNotCreatedException
    • The browser launches in headless mode regardless of the configuration

    Answer: The session initialization fails, usually throwing a SessionNotCreatedException. Compatibility is enforced strictly; an old driver cannot communicate with a newer browser API. Option 1 and 2 are incorrect because the handshake happens before the browser fully loads. Option 4 is wrong as it doesn't change the execution mode.

    From lesson: Setting Up WebDriver — Chrome and Firefox

  9. In a modern Selenium environment, what is the most reliable way to ensure a clean browser state for every test case?

    • Clearing the browser cache folder manually after every test
    • Restarting the computer to clear temporary files
    • Calling driver.quit() to properly close the browser and end the driver session
    • Invoking browser.refresh() at the beginning of each test

    Answer: Calling driver.quit() to properly close the browser and end the driver session. driver.quit() sends a termination signal to the driver process, ensuring the session is cleaned up. Option 1 is impractical. Option 2 is unnecessary. Option 4 only reloads the page, which does not reset cookies or local storage effectively.

    From lesson: Setting Up WebDriver — Chrome and Firefox

  10. When configuring Firefox for automation, which capability is most critical to address if you want to avoid security certificate errors?

    • Setting the 'acceptInsecureCerts' capability to true
    • Disabling the internet connection during the test
    • Installing the browser in a specific system directory
    • Manually confirming the certificate warning through UI interactions

    Answer: Setting the 'acceptInsecureCerts' capability to true. Selenium provides built-in capabilities to handle insecure site warnings automatically. Option 1 is the intended way to handle this. Option 2 would prevent the browser from loading pages. Option 3 has no effect on certificates. Option 4 is inefficient and brittle compared to using driver capabilities.

    From lesson: Setting Up WebDriver — Chrome and Firefox

  11. Why is setting a window size critical when running Selenium in headless mode?

    • It prevents the browser from crashing due to memory constraints.
    • It ensures that elements are rendered in the desktop view rather than the mobile view.
    • It is required to initialize the driver session.
    • It simulates a faster CPU processing speed.

    Answer: It ensures that elements are rendered in the desktop view rather than the mobile view.. The correct answer is the second option because headless browsers default to small windows, which often trigger mobile-responsive CSS, hiding elements. Option 1 is incorrect as it relates to memory, not layout. Option 3 is false because drivers can initialize without specific sizes. Option 4 is irrelevant to window dimensions.

    From lesson: Headless Browser Testing

  12. If a test fails in headless mode but passes in visible mode, what is the most likely cause?

    • The browser driver is corrupted.
    • The script is trying to interact with an element that is technically not visible due to lack of rendering.
    • The network speed is being throttled by the headless option.
    • Selenium requires a physical monitor connected to the server.

    Answer: The script is trying to interact with an element that is technically not visible due to lack of rendering.. The second option is correct because headless mode skips UI rendering; elements with 'hidden' properties or complex CSS animations may not be 'interactable' in the same way. The other options are incorrect because they describe unrelated environmental or software issues.

    From lesson: Headless Browser Testing

  13. How should you handle an element that fails to be clicked in headless mode because it is obscured by another layer?

    • Increase the wait time until the element appears.
    • Restart the browser instance.
    • Use an Actions class to click or execute JavaScript to trigger the click.
    • Disable headless mode permanently.

    Answer: Use an Actions class to click or execute JavaScript to trigger the click.. The third option is correct because JavaScript execution circumvents UI constraints like visibility or overlaps. Increasing wait time (Option 1) doesn't fix a logic-based obstruction. Restarting (Option 2) is a waste of resources. Disabling (Option 4) negates the purpose of the headless testing strategy.

    From lesson: Headless Browser Testing

  14. When testing a website that blocks non-browser traffic, which headless configuration is essential?

    • Setting the language to English.
    • Setting a proper User-Agent string to mimic a standard browser.
    • Disabling cookies entirely.
    • Running the test with administrative privileges.

    Answer: Setting a proper User-Agent string to mimic a standard browser.. The second option is correct because servers often reject the default headless User-Agent to block bots. Option 1 is irrelevant to access. Option 3 would likely break site functionality. Option 4 is a security risk and does not influence browser identification.

    From lesson: Headless Browser Testing

  15. What is the primary architectural advantage of using headless browser testing in a CI/CD pipeline?

    • It eliminates the need for any kind of wait logic in the test script.
    • It allows for faster execution and lower resource consumption on build servers.
    • It automatically fixes bugs found in the code.
    • It ensures the website is compatible with mobile devices only.

    Answer: It allows for faster execution and lower resource consumption on build servers.. The second option is correct as headless browsers run faster and consume less RAM than full GUI browsers. Option 1 is false as waiting logic is still mandatory. Option 3 is incorrect because tests only detect, not fix. Option 4 is incorrect because headless tests can simulate various resolutions.

    From lesson: Headless Browser Testing

  16. When should you prefer a CSS selector over an XPath expression?

    • When you need to navigate to a parent element from a child element.
    • When you want to select an element based on its text content.
    • When you prioritize execution speed and readability for simple element selection.
    • When you need to perform complex index-based filtering of elements.

    Answer: When you prioritize execution speed and readability for simple element selection.. CSS selectors are generally faster and cleaner for simple lookups. Option 0 and 3 describe XPath capabilities (parent traversal and complex indexing), while option 1 describes XPath's ability to locate by text, which CSS lacks.

    From lesson: Locating Elements — ID, Name, CSS, XPath

  17. What is the primary risk of using the 'find_element_by_xpath' method with a dynamic attribute like a timestamp?

    • The element will be found, but the interaction will fail due to timing.
    • The locator will become invalid as soon as the page is refreshed or the dynamic value changes.
    • The browser will refuse to parse the XPath string if it contains numbers.
    • The locator will match too many elements, causing a crash.

    Answer: The locator will become invalid as soon as the page is refreshed or the dynamic value changes.. Dynamic attributes change on every page load. Option 0 is about timing, not locator validity; option 2 is incorrect because XPaths can contain numbers; option 3 is incorrect because a non-unique match would return the first occurrence, not crash.

    From lesson: Locating Elements — ID, Name, CSS, XPath

  18. How does using a partial match in CSS or XPath improve test stability?

    • It prevents the script from throwing a syntax error.
    • It forces the browser to ignore hidden elements.
    • It allows elements to be identified even if minor, irrelevant parts of their attributes change.
    • It automatically increases the timeout period for that specific element.

    Answer: It allows elements to be identified even if minor, irrelevant parts of their attributes change.. Partial matching (e.g., [id*='submit']) is useful for IDs that have a static base and a dynamic suffix. Options 0, 1, and 3 describe behaviors not inherent to string partial matching.

    From lesson: Locating Elements — ID, Name, CSS, XPath

  19. If multiple elements match a locator provided to 'find_element', which one does Selenium return?

    • The last element found in the DOM.
    • An error is thrown indicating multiple elements exist.
    • The first element it encounters while traversing the DOM.
    • A random element from the matching set.

    Answer: The first element it encounters while traversing the DOM.. Selenium returns the first matching element. It does not error (unless you specifically ask for a list and check length), nor is it random or last-based.

    From lesson: Locating Elements — ID, Name, CSS, XPath

  20. Why is 'ID' considered the gold standard for locating elements in Selenium?

    • It is guaranteed to be unique and generally remains stable even if the layout changes.
    • It is the only attribute that the browser's engine can read without CSS parsing.
    • It allows for the inclusion of multiple conditions within the same selector.
    • It is always visible to the user, ensuring the element is interactive.

    Answer: It is guaranteed to be unique and generally remains stable even if the layout changes.. IDs are developer-assigned and typically stable. Option 1 is false (CSS parses IDs fine), option 2 describes XPath's advantage, and option 3 is false as IDs are often used for background logic and may be hidden.

    From lesson: Locating Elements — ID, Name, CSS, XPath

  21. Which approach is most robust when handling an input field that triggers a dropdown menu upon typing?

    • Use a fixed thread sleep duration after every key stroke
    • Use explicit waits to ensure the dropdown menu element is present after the typing action
    • Send all characters at once using a single sendKeys command
    • Disable the dropdown functionality using browser settings

    Answer: Use explicit waits to ensure the dropdown menu element is present after the typing action. Option 1 is bad practice as it causes flakiness. Option 3 might miss the trigger if the app needs to process characters individually. Option 4 is not a functional test. Option 2 is correct because it synchronizes the test with the application state.

    From lesson: Clicking, Typing, and Submitting

  22. When is it appropriate to use JavaScript Executor to perform a click instead of the standard click() method?

    • When the standard click() method is slightly too slow
    • When you want to bypass browser security policies
    • When an element is covered by another transparent element that prevents standard interaction
    • When you need to test the performance of the mouse click event

    Answer: When an element is covered by another transparent element that prevents standard interaction. Option 1 and 4 are irrelevant to functionality. Option 2 is not the purpose of JS Executor. Option 3 is correct because JS Executor interacts directly with the DOM, bypassing UI layers that obstruct standard Selenium clicks.

    From lesson: Clicking, Typing, and Submitting

  23. Why is it recommended to chain keys like 'Keys.chord(Keys.CONTROL, "a"), Keys.BACK_SPACE' before typing into a field?

    • It is faster than the clear() method
    • It ensures that text formatted as a single entity is fully removed, which clear() might miss
    • It prevents the browser from closing the tab
    • It is the only way to interact with text fields in Selenium

    Answer: It ensures that text formatted as a single entity is fully removed, which clear() might miss. Option 3 and 4 are incorrect. Option 1 is false. Option 2 is correct because some frameworks maintain internal states that simple clear() calls don't reset, while selecting all text and deleting it triggers the necessary input events.

    From lesson: Clicking, Typing, and Submitting

  24. What happens if you attempt to submit a form by clicking a button that is currently outside the viewport?

    • The action will always succeed because the element is in the DOM
    • The action will fail unless the driver scrolls to the element first
    • The browser will automatically resize the window to fit the button
    • The test will pause until you manually scroll to the element

    Answer: The action will fail unless the driver scrolls to the element first. Option 1 is wrong because Selenium requires the element to be interactable. Option 3 and 4 do not happen automatically. Option 2 is correct because most modern drivers require an element to be within the viewable area to receive pointer events.

    From lesson: Clicking, Typing, and Submitting

  25. If a text field updates dynamically based on user input, what is the best way to verify the input was accepted?

    • Check the 'value' attribute of the input element after the sendKeys action
    • Wait for a specific amount of time and then proceed
    • Assume the action succeeded if no error was thrown
    • Refresh the page to check the data

    Answer: Check the 'value' attribute of the input element after the sendKeys action. Option 1 is the most reliable way to verify state. Option 2 is flaky, Option 3 ignores potential failures, and Option 4 would wipe the state you are trying to verify.

    From lesson: Clicking, Typing, and Submitting

  26. When working with a <select> element, why is the 'Select' class preferred over standard click actions?

    • It is faster because it bypasses the browser's rendering engine entirely.
    • It handles the necessary expansion and selection logic internally, making the script more robust.
    • It is the only way to interact with non-standard dropdowns.
    • It automatically waits for the dropdown to become visible without explicit waits.

    Answer: It handles the necessary expansion and selection logic internally, making the script more robust.. The Select class is designed specifically for standard HTML dropdowns, ensuring state changes are handled reliably. Standard clicks can fail if the dropdown isn't in view or is obscured; other options are false because the class doesn't bypass rendering or handle all custom dropdowns.

    From lesson: Dropdowns, Checkboxes, and Alerts

  27. What is the most reliable way to toggle a checkbox that might already be selected?

    • Clicking the element regardless of its current state.
    • Clearing the element before clicking it.
    • Checking the 'selected' property and only clicking if it is false.
    • Sending a 'space' key press to the element.

    Answer: Checking the 'selected' property and only clicking if it is false.. Checking the state first prevents accidental deselecting. Clearing is for input fields, not checkboxes. Clicking blindly can toggle it to the wrong state, and sending keys is less reliable than checking the attribute.

    From lesson: Dropdowns, Checkboxes, and Alerts

  28. Why does a test fail with NoAlertPresentException even when the alert is visible to the human eye?

    • The alert needs to be switched to using driver.switchTo().alert().
    • The browser driver requires a specific window handle to be set first.
    • The execution speed is faster than the browser's alert creation event.
    • The alert is actually an HTML-based modal, not a native browser alert.

    Answer: The execution speed is faster than the browser's alert creation event.. This is a timing issue. Selenium moves faster than the alert pop-up event. Switching to the alert (option 1) is what you do after finding it, not the cause of the exception. HTML modals are not handled by the alert interface.

    From lesson: Dropdowns, Checkboxes, and Alerts

  29. If you have a dropdown that requires a specific option to be selected by its visible text, what is the best approach?

    • Use an XPath locator with the text content and click the element.
    • Instantiate a Select object and call selectByVisibleText().
    • Use executeScript to change the value attribute of the select tag.
    • Loop through all options and click the one that matches.

    Answer: Instantiate a Select object and call selectByVisibleText().. selectByVisibleText() is the purpose-built method for this task. XPath clicks (option 1) and looping (option 4) are brittle, while executeScript (option 3) bypasses the user-interaction layer which may be needed to trigger JavaScript events.

    From lesson: Dropdowns, Checkboxes, and Alerts

  30. How do you handle an alert that appears only after a conditional background process?

    • Use a static thread sleep to ensure the alert appears.
    • Use an explicit wait combined with ExpectedConditions.alertIsPresent().
    • Use a try-catch block to handle the potential alert presence.
    • Check the page source for the existence of an alert tag.

    Answer: Use an explicit wait combined with ExpectedConditions.alertIsPresent().. ExpectedConditions.alertIsPresent() is the correct way to handle dynamic timing. Thread sleep is poor practice, try-catch is a messy workaround, and page source does not contain native browser alerts.

    From lesson: Dropdowns, Checkboxes, and Alerts

  31. Why does a NoSuchElementException occur even though the element is visible on the screen?

    • The element is located inside an iframe that has not been switched into.
    • The browser driver is out of date.
    • The element is obscured by a modal dialog.
    • The page took too long to load initially.

    Answer: The element is located inside an iframe that has not been switched into.. Elements inside an iframe are in a different browsing context. Option 0 is correct because Selenium requires an explicit switch to the frame's context. The other options refer to environment or visual issues that usually trigger different error types or require different handling methods.

    From lesson: Handling iframes

  32. What is the correct sequence to interact with an element inside a deeply nested iframe?

    • Find the inner frame directly using XPath and switch to it.
    • Switch to the main frame, then switch to the child frame, then locate the element.
    • Use a global search to find the element regardless of the frame.
    • Execute a script to remove the iframe tags from the DOM.

    Answer: Switch to the main frame, then switch to the child frame, then locate the element.. Selenium requires navigating the frame hierarchy. Option 1 is correct because you must follow the parent-child structure. Option 0 fails because browsers cannot target nested frames directly. Options 2 and 3 are conceptually incorrect as they ignore the iframe security boundaries.

    From lesson: Handling iframes

  33. What is the effect of calling switchTo().defaultContent()?

    • It closes the currently active iframe.
    • It refreshes the browser page.
    • It returns the focus to the main page level of the document.
    • It switches the focus to the parent iframe of the current one.

    Answer: It returns the focus to the main page level of the document.. Option 2 correctly defines the method's purpose of resetting focus to the top-level window. Option 3 is incorrect because 'parent frame' switching is handled by a different method, while the other options describe actions the method does not perform.

    From lesson: Handling iframes

  34. If you need to switch to a parent iframe from a child iframe, which method should be used?

    • switchTo().defaultContent()
    • switchTo().parentFrame()
    • switchTo().frame(0)
    • switchTo().window('parent')

    Answer: switchTo().parentFrame(). Option 1 is the intended method for moving one level up in the frame hierarchy. Option 0 would jump to the top, not the immediate parent. The other options are either for switching to indices or browsers, which is not the correct scope here.

    From lesson: Handling iframes

  35. When is it appropriate to use driver.switchTo().frame(WebElement)?

    • When the frame is identified by its string ID or Name attribute.
    • When you have already located the iframe element using a locator.
    • When you want to switch to the frame that contains the current focus.
    • When the page has multiple iframes and you want to switch to all of them at once.

    Answer: When you have already located the iframe element using a locator.. Option 1 allows the user to pass a WebElement object representing the iframe, which is useful for dynamic frames. Option 0 is for frame ID/Name strings. The other options are invalid as you cannot switch to multiple frames at once or switch to the frame containing current focus in that manner.

    From lesson: Handling iframes

  36. What is the primary scope of an Implicit Wait in Selenium?

    • It applies to the entire lifetime of the WebDriver instance
    • It applies only to the next command executed
    • It applies to a specific locator strategy defined in a function
    • It applies only to page navigation events

    Answer: It applies to the entire lifetime of the WebDriver instance. Implicit waits are set globally on the WebDriver instance. Option 1 is correct. Option 2 describes Explicit waits, Option 3 is non-existent functionality, and Option 4 is incorrect as it covers all findElement calls.

    From lesson: Implicit Waits

  37. If you set an implicit wait of 10 seconds, what happens when you call findElement() for an element that does not exist?

    • The script throws a NoSuchElementException immediately
    • The script pauses for 10 seconds before throwing a NoSuchElementException
    • The script waits until the page finishes loading completely
    • The script retries finding the element every 10 seconds

    Answer: The script pauses for 10 seconds before throwing a NoSuchElementException. Implicit wait forces the driver to poll the DOM for 10 seconds before giving up. Option 1 ignores the wait, Option 3 describes a PageLoad strategy, and Option 4 misinterprets the polling frequency.

    From lesson: Implicit Waits

  38. Which of the following scenarios is best suited for an Implicit Wait?

    • Waiting for an element to become clickable
    • Waiting for an element to be present in the DOM
    • Waiting for a specific text to appear in a dynamic element
    • Waiting for a modal to become invisible

    Answer: Waiting for an element to be present in the DOM. Implicit wait only checks for presence in the DOM. Option 1, 3, and 4 require checking element states (interactability/invisibility), which is only possible with Explicit Waits.

    From lesson: Implicit Waits

  39. What occurs when you set an Implicit Wait to 5 seconds, and then later set it to 10 seconds in the same test?

    • The driver adds the times, resulting in a 15-second wait
    • The driver uses the 5-second wait for current elements and 10-second for new ones
    • The new 10-second duration overrides the previous 5-second setting
    • The driver throws an error because the wait was already configured

    Answer: The new 10-second duration overrides the previous 5-second setting. Implicit wait settings are global properties that are overwritten by subsequent calls. Options 1, 2, and 4 incorrectly describe how the driver manages configuration state.

    From lesson: Implicit Waits

  40. Why is it generally discouraged to use Implicit Waits in modern Selenium testing?

    • They are deprecated and will be removed in future versions
    • They cannot be used with CSS Selectors
    • They lack the granularity to handle complex synchronization scenarios
    • They cause memory leaks in the WebDriver process

    Answer: They lack the granularity to handle complex synchronization scenarios. Implicit waits lack the ability to wait for specific conditions (visibility, invisibility, attribute changes). Option 1 is false (they are not deprecated), Option 2 is false (they work with all locators), and Option 4 is false.

    From lesson: Implicit Waits

  41. When should you prefer an Explicit Wait over an Implicit Wait in a Selenium project?

    • When you want the driver to wait globally for all elements to be present
    • When you need to wait for a specific condition, such as an element becoming clickable or a text change
    • When you want to increase the speed of the script execution globally
    • When you want to avoid using the WebDriverWait class entirely

    Answer: When you need to wait for a specific condition, such as an element becoming clickable or a text change. Explicit waits allow you to define conditions for specific elements, which is more robust. Implicit waits are global and can cause unintended delays. Options 1 and 3 describe global settings, and option 4 ignores the primary tool for explicit synchronization.

    From lesson: Explicit Waits — WebDriverWait and Expected Conditions

  42. What happens if an ExpectedCondition is not met within the timeout period defined in WebDriverWait?

    • The driver returns null
    • The driver moves to the next line of code
    • A TimeoutException is thrown
    • The driver automatically retries the action indefinitely

    Answer: A TimeoutException is thrown. WebDriverWait is designed to throw a TimeoutException when the condition fails, allowing you to catch it. It does not return null, skip lines, or retry indefinitely, as that would hang the test suite.

    From lesson: Explicit Waits — WebDriverWait and Expected Conditions

  43. Why is 'elementToBeClickable' often a better choice than 'visibilityOfElementLocated' for button interactions?

    • It checks if the element is present in the DOM, whereas visibility only checks for style
    • It verifies both visibility and the enabled state, ensuring the element can actually receive a click
    • It is faster than checking for visibility
    • It forces the driver to click the element automatically

    Answer: It verifies both visibility and the enabled state, ensuring the element can actually receive a click. An element might be visible but disabled; 'elementToBeClickable' confirms both visibility and enabled status. Visibility only checks if the element is rendered, and it doesn't perform automatic clicks.

    From lesson: Explicit Waits — WebDriverWait and Expected Conditions

  44. What is the primary function of the polling interval in a WebDriverWait instance?

    • It dictates how long the driver waits before starting to look for the element
    • It defines the frequency at which the driver re-evaluates the ExpectedCondition
    • It limits the maximum number of times the driver can refresh the page
    • It sets the default wait time for all elements in the script

    Answer: It defines the frequency at which the driver re-evaluates the ExpectedCondition. The polling interval defines how often the driver checks if the condition has been met during the timeout period. The other options refer to timeout durations or page interactions, not the polling mechanism.

    From lesson: Explicit Waits — WebDriverWait and Expected Conditions

  45. If you are waiting for a specific text to appear in an element, which approach is most efficient?

    • Use thread.sleep to wait for a fixed amount of time
    • Use an implicit wait and then manually loop through the text
    • Use WebDriverWait with textToBePresentInElementLocated
    • Wait for the element to be present, then use an if-statement to check the text

    Answer: Use WebDriverWait with textToBePresentInElementLocated. textToBePresentInElementLocated is a built-in ExpectedCondition specifically optimized for this scenario. Thread.sleep is unstable and slow, manual looping is redundant, and an if-statement lacks the necessary synchronization logic to wait for the DOM to update.

    From lesson: Explicit Waits — WebDriverWait and Expected Conditions

  46. What is the primary technical advantage of using FluentWait over a standard WebDriverWait?

    • It executes tests faster by bypassing the DOM
    • It allows for custom polling intervals and ignoring specific exceptions
    • It automatically closes the browser session upon timeout
    • It reduces the total execution time of the entire test suite to zero

    Answer: It allows for custom polling intervals and ignoring specific exceptions. The primary advantage is flexibility in polling frequency and exception handling. Option 0 is false as it does not bypass the DOM. Option 2 is false as wait classes don't control browser lifecycle. Option 3 is false as wait times cannot make execution faster than the application responds.

    From lesson: Fluent Waits

  47. If you configure a FluentWait with a 30-second timeout and a 5-second polling interval, what happens if the condition is met at 2 seconds?

    • The script waits until the 5-second mark to continue
    • The script waits until the 30-second mark to ensure stability
    • The script proceeds immediately to the next line of code
    • The script throws an exception because the poll did not complete

    Answer: The script proceeds immediately to the next line of code. FluentWait checks the condition at the poll intervals but stops immediately once the condition returns true. Option 0 and 1 are incorrect as they imply unnecessary waiting. Option 3 is incorrect because the wait is designed to succeed when the condition is met.

    From lesson: Fluent Waits

  48. Which of the following is the most appropriate use case for a FluentWait?

    • Waiting for a static page title to load
    • Handling a dynamic element that intermittently throws a StaleElementReferenceException
    • Waiting for a fixed 10 seconds before typing in a text field
    • Replacing all instances of Thread.sleep() in the code

    Answer: Handling a dynamic element that intermittently throws a StaleElementReferenceException. FluentWait is ideal for handling intermittent errors like StaleElementReferenceException via the ignoring method. Option 0 is a standard WebDriverWait case. Option 2 is a misuse of polling. Option 3 is bad practice as it ignores the 'dynamic' nature of web testing.

    From lesson: Fluent Waits

  49. Why should the polling interval be smaller than the total timeout duration?

    • To ensure the script checks for the element multiple times before timing out
    • To prevent the browser from crashing due to memory overflow
    • To satisfy the requirements of the internal Selenium clock
    • To increase the speed of the browser rendering engine

    Answer: To ensure the script checks for the element multiple times before timing out. Polling exists specifically to check multiple times. If the interval equals the timeout, it only checks once, rendering the wait useless. Other options are irrelevant to the function of polling intervals.

    From lesson: Fluent Waits

  50. What happens if a FluentWait reaches its total timeout limit without the condition being satisfied?

    • It returns a null object and continues
    • It throws a TimeoutException
    • It automatically retries the entire test method
    • It clears the browser cache and attempts to reload

    Answer: It throws a TimeoutException. When the timeout period expires, Selenium throws a TimeoutException to indicate the condition was never met. The other options describe actions that the wait mechanism does not perform.

    From lesson: Fluent Waits

  51. When a developer updates the ID of a 'Login' button, what is the primary benefit of having implemented the Page Object Model?

    • The test execution speed automatically increases.
    • Only the specific Page Object class needs to be modified, leaving test scripts untouched.
    • Selenium automatically detects the locator change during runtime.
    • The browser driver will automatically update the locator in the DOM.

    Answer: Only the specific Page Object class needs to be modified, leaving test scripts untouched.. Option 1 is correct because POM encapsulates locators, localizing maintenance. Option 0 is irrelevant to structure; Option 2 is false as Selenium cannot self-heal locators without custom wrappers; Option 3 is false as DOM is controlled by the app, not the driver.

    From lesson: Page Object Model (POM) Pattern

  52. Why is it considered a bad practice to perform assertions inside your Page Object methods?

    • It prevents the use of PageFactory for initialization.
    • It makes the Page Object class too dependent on the test execution environment.
    • It violates the principle that Page Objects should represent the page structure, not define test success criteria.
    • Selenium does not support the Assert class within page classes.

    Answer: It violates the principle that Page Objects should represent the page structure, not define test success criteria.. Option 2 is correct because Page Objects model the UI; test assertions define intent. Option 0 is incorrect; Option 1 is vague; Option 3 is incorrect as the framework doesn't restrict it, but logic does.

    From lesson: Page Object Model (POM) Pattern

  53. Which of the following describes the ideal interaction between a Test Script and a Page Object?

    • The Test Script directly calls driver.findElement() using locators defined in the test file.
    • The Test Script invokes high-level service methods provided by the Page Object.
    • The Test Script accesses private WebElement variables directly from the Page Object.
    • The Test Script overrides the Page Object's constructor to inject custom driver settings.

    Answer: The Test Script invokes high-level service methods provided by the Page Object.. Option 1 is correct because it encapsulates behavior into reusable methods. Option 0 bypasses POM; Option 2 breaks encapsulation; Option 3 is a misuse of design patterns.

    From lesson: Page Object Model (POM) Pattern

  54. In a robust implementation, how should a Page Object handle a situation where a user must wait for an element to load after a button click?

    • Use a static sleep command to ensure the network has time to respond.
    • Expect the test script to handle the wait before calling the next Page Object method.
    • Implement explicit waits inside the method that performs the interaction.
    • Rely on the default implicit wait set at the driver level for all interactions.

    Answer: Implement explicit waits inside the method that performs the interaction.. Option 2 is correct as it keeps the page logic self-contained. Option 0 is poor practice; Option 1 forces test scripts to know too much about page behavior; Option 3 is less reliable than explicit waits.

    From lesson: Page Object Model (POM) Pattern

  55. What is the primary architectural goal of using Page Object Model in a Selenium suite?

    • To maximize the amount of code shared between the UI and the backend API.
    • To achieve a clean separation between the test logic and the application's UI implementation details.
    • To automatically generate HTML reports of the test failures.
    • To eliminate the need for using locators like XPaths or CSS Selectors.

    Answer: To achieve a clean separation between the test logic and the application's UI implementation details.. Option 1 is the definition of POM. Option 0 is unrelated; Option 2 is a byproduct of reporting tools; Option 3 is impossible as elements must always be located.

    From lesson: Page Object Model (POM) Pattern

  56. Which interface must a WebDriver instance be cast to in order to access the screenshot capability?

    • WebDriver
    • TakesScreenshot
    • JavascriptExecutor
    • WebElement

    Answer: TakesScreenshot. TakesScreenshot is the specific interface containing the getScreenshotAs method. WebDriver is the base, JavascriptExecutor runs scripts, and WebElement refers to page components, not the browser capability itself.

    From lesson: Taking Screenshots

  57. What is the primary reason for a 'NoSuchWindowException' when attempting to take a screenshot?

    • The driver was not cast to TakesScreenshot
    • The file output path is incorrect
    • The target window or tab was closed before the command executed
    • The image format specified is not supported

    Answer: The target window or tab was closed before the command executed. If the browser window or frame is closed, the driver loses its context. Casting issues result in ClassCastException, while file path issues result in IOException.

    From lesson: Taking Screenshots

  58. If you need to capture only a specific button rather than the whole screen, what is the best approach?

    • Call getScreenshotAs on the WebElement object directly
    • Take a full screenshot and use an external image library to crop it
    • Use a CSS property to hide all other elements before taking the screenshot
    • The standard WebDriver implementation only supports full-page or viewport captures

    Answer: Call getScreenshotAs on the WebElement object directly. Modern implementations of the WebElement interface provide a getScreenshotAs method which limits the capture area to the element's bounding box. The others are either workarounds or incorrect assumptions.

    From lesson: Taking Screenshots

  59. Why is it recommended to perform an explicit wait before calling getScreenshotAs?

    • To ensure the operating system has enough memory to process the image
    • To guarantee the rendering engine has finished drawing the UI elements
    • To prevent the browser from crashing due to high-frequency events
    • To verify that the file system is ready for writing

    Answer: To guarantee the rendering engine has finished drawing the UI elements. Screenshots are visual representations of the DOM; if you capture before the UI is rendered, you get partial or incorrect state. Waiting for elements ensures the visual state is consistent with the logical state.

    From lesson: Taking Screenshots

  60. When using 'OutputType.FILE', what happens to the resulting file after the test process terminates?

    • It is automatically deleted by the driver
    • It is moved to a temporary directory
    • It remains in the specified location until manually removed
    • It is automatically uploaded to the test report server

    Answer: It remains in the specified location until manually removed. Selenium creates the file at the path you provide and does not manage its lifecycle. It is the responsibility of the developer to manage cleanup. It is not deleted or uploaded by the framework by default.

    From lesson: Taking Screenshots

  61. When a new window is opened by an action, why does a test script often fail to find elements inside the new window?

    • Selenium automatically switches to the most recently opened window
    • The driver context remains locked to the original window until explicitly switched
    • The new window is considered an iframe and requires switchTo().frame()
    • Selenium cannot interact with secondary windows due to security restrictions

    Answer: The driver context remains locked to the original window until explicitly switched. Selenium's focus is persistent; it doesn't track window transitions automatically. Option 0 is false because there is no automatic focus shift. Option 2 is incorrect because tabs are separate handles, not frames. Option 3 is false as Selenium supports multiple windows perfectly.

    From lesson: Handling Multiple Windows and Tabs

  62. Which of the following is the most robust way to switch to a specific new window?

    • Using driver.switchTo().window(String.valueOf(1))
    • Looping through getWindowHandles() and comparing current window titles
    • Always assuming the last handle in the Set is the new window
    • Using driver.switchTo().activeElement()

    Answer: Looping through getWindowHandles() and comparing current window titles. Handles are unpredictable strings, so comparing unique attributes like titles or URLs is safer than index assumptions. Option 0 uses an invalid type, Option 2 is risky if windows close/reopen, and Option 3 targets an element, not a window.

    From lesson: Handling Multiple Windows and Tabs

  63. What is the difference between driver.close() and driver.quit()?

    • close() closes the browser session, quit() closes only the current tab
    • close() closes the current window, quit() ends the driver session and all windows
    • close() is for windows, quit() is only for alerts
    • They perform the exact same function in all browser drivers

    Answer: close() closes the current window, quit() ends the driver session and all windows. close() targets the focused window handle, while quit() kills the process and clears the session. The other options misidentify the scope or the intended purpose of the termination methods.

    From lesson: Handling Multiple Windows and Tabs

  64. After performing an action in a new window, how do you return to the parent window?

    • Use driver.switchTo().defaultContent()
    • Call driver.navigate().back()
    • Switch back to the stored original handle using driver.switchTo().window()
    • Close the new window and Selenium will automatically focus the previous one

    Answer: Switch back to the stored original handle using driver.switchTo().window(). You must maintain a reference to the initial handle. defaultContent() is for iframes, navigate().back() changes history, and Selenium does not track or switch focus automatically upon closing a window.

    From lesson: Handling Multiple Windows and Tabs

  65. Why should you use an explicit wait (like ExpectedConditions) before switching windows?

    • To ensure the new window handle has been added to the session's set of handles
    • To allow the CSS of the new window to load completely
    • To bypass security pop-up blocks in the browser
    • To prevent the browser from crashing during a memory-intensive operation

    Answer: To ensure the new window handle has been added to the session's set of handles. The browser might open a window handle asynchronously, so checking that the handle exists in the set prevents NoSuchWindowException. The other options are incorrect as they do not address the timing of window handle availability.

    From lesson: Handling Multiple Windows and Tabs

  66. When is it appropriate to use executeScript instead of standard WebElement interactions?

    • When you want your automation to run faster than a human
    • When the element is covered by another element or hidden from the UI
    • Whenever you want to guarantee 100% test reliability
    • When you need to debug the CSS properties of an object

    Answer: When the element is covered by another element or hidden from the UI. Option 2 is correct because JavaScriptExecutor can interact with the DOM directly, bypassing UI obstructions. Option 1 is incorrect because speed is not a standard justification. Option 3 is wrong as JS interaction can hide bugs where elements are not actually interactable by users. Option 4 is incorrect because standard getters handle CSS property checks.

    From lesson: JavaScript Executor

  67. What happens if you execute a script that does not include the 'return' keyword?

    • The script will throw a ScriptTimeoutException
    • The driver will automatically return the last evaluated expression
    • The method will return a null object
    • The browser will automatically refresh the page

    Answer: The method will return a null object. Option 3 is correct; without an explicit return in the string, the WebDriver object receives no output. Option 1 is incorrect as timing is separate. Option 2 is a common misconception about JS scope. Option 4 is incorrect as refreshing is not a side effect of execution.

    From lesson: JavaScript Executor

  68. If you pass a WebElement as an argument to a script, how does JavaScript access it?

    • By its ID attribute only
    • As an 'arguments' array index
    • Through the global window object
    • By its XPath string value

    Answer: As an 'arguments' array index. Option 2 is correct; arguments are passed via the 'arguments' array (e.g., arguments[0]). Option 1 is incorrect as it restricts access to ID. Option 3 is wrong as arguments are scoped to the execution context. Option 4 is incorrect as the object itself is passed as a reference, not a query string.

    From lesson: JavaScript Executor

  69. Why is it recommended to check 'instanceof JavascriptExecutor' before casting?

    • To prevent a ClassCastException at runtime
    • To increase the execution speed of the script
    • To ensure the browser is fully loaded
    • To automatically clear the browser cache

    Answer: To prevent a ClassCastException at runtime. Option 0 is correct as not all WebDriver implementations support script execution. Options 1, 2, and 3 are incorrect because checking the instance type does not impact performance, browser load state, or cache management.

    From lesson: JavaScript Executor

  70. What is the primary difference between executeScript and executeAsyncScript?

    • executeAsyncScript supports more complex mathematical functions
    • executeScript is for CSS while executeAsyncScript is for HTML
    • executeAsyncScript requires a callback function to signal completion
    • executeScript cannot return values to the test suite

    Answer: executeAsyncScript requires a callback function to signal completion. Option 2 is correct; executeAsyncScript forces the driver to wait until a callback is invoked. Option 1 is false. Option 3 is false as both handle different syntaxes. Option 4 is false as executeScript does return values.

    From lesson: JavaScript Executor

  71. What is the primary architectural responsibility of the Hub in a Selenium Grid setup?

    • It executes the actual test scripts on the connected browsers.
    • It serves as the central entry point that routes test requests to the appropriate registered node.
    • It stores all test reports and screenshots generated during the execution process.
    • It converts Selenium commands into browser-specific native events.

    Answer: It serves as the central entry point that routes test requests to the appropriate registered node.. The Hub acts as a router/manager. Option 0 is wrong because the nodes execute tests. Option 2 is wrong because reporting is done by testing frameworks, not the Hub. Option 3 is wrong because that is the role of the WebDriver/browser driver.

    From lesson: Selenium Grid

  72. When configuring a Node, why is it necessary to pass a configuration JSON file or specific arguments?

    • To encrypt the traffic between the Hub and the Node.
    • To define the browser types, versions, and maximum concurrent sessions the Node can handle.
    • To automatically download the latest browser drivers for the machine.
    • To force the Node to restart every time a test finishes.

    Answer: To define the browser types, versions, and maximum concurrent sessions the Node can handle.. The Hub needs to know the capabilities of the Node to match incoming requests. Option 0 is incorrect as encryption is a network configuration, not a Grid feature. Option 2 is incorrect as driver management is external. Option 3 is incorrect as frequent restarts would degrade performance.

    From lesson: Selenium Grid

  73. If a test requires 'Chrome, Version 90' but the grid only has 'Chrome, Version 88' nodes, what will happen?

    • The Hub will force the test to run on Version 88.
    • The test will automatically fail with a timeout error.
    • The Hub will queue the test indefinitely until a matching node becomes available.
    • The Grid will automatically update the browser version on the Node.

    Answer: The Hub will queue the test indefinitely until a matching node becomes available.. The Hub matches capabilities. If no match is found, the request stays in the queue until a timeout occurs. Option 0 is wrong because it doesn't downgrade versions. Option 1 is wrong because it isn't an immediate timeout. Option 3 is wrong because Selenium cannot update host browsers.

    From lesson: Selenium Grid

  74. How does the 'DesiredCapabilities' or 'Options' object impact the Grid execution flow?

    • It instructs the Hub on which specific node to select based on the criteria provided.
    • It defines the network speed of the test execution.
    • It stores the authentication credentials for the Hub's administration panel.
    • It changes the language the test code is written in.

    Answer: It instructs the Hub on which specific node to select based on the criteria provided.. The Hub uses these objects to filter registered nodes. Options 1, 2, and 3 are irrelevant to the capability matching process handled by the Hub.

    From lesson: Selenium Grid

  75. Why is it recommended to use a high-performance machine for the Hub in large-scale grids?

    • The Hub renders the screenshots for all parallel test sessions.
    • The Hub is responsible for processing, queuing, and managing the request traffic for all connected nodes.
    • The Hub needs to store all browser binaries in its local memory.
    • The Hub performs all the object identification logic for every test.

    Answer: The Hub is responsible for processing, queuing, and managing the request traffic for all connected nodes.. The Hub manages the orchestration layer; heavy traffic requires CPU/RAM. Option 0 is wrong because rendering happens on the node. Option 2 is wrong because binaries are on the nodes. Option 3 is wrong because the node handles object identification.

    From lesson: Selenium Grid

  76. When should you prefer an Explicit Wait over an Implicit Wait in your automation framework?

    • When you want to set a global timeout for the entire duration of the test suite
    • When dealing with elements that appear or change state dynamically on the page
    • When you have a very fast network connection and want to avoid any delays
    • When you want to ensure the browser has fully loaded all third-party tracking scripts

    Answer: When dealing with elements that appear or change state dynamically on the page. Explicit waits are preferred for dynamic elements because they target specific conditions. Implicit waits are global settings that can cause unpredictable behavior and unnecessary delays when mixed with explicit waits, whereas the other options do not address the primary goal of handling conditional synchronization.

    From lesson: Playwright vs Selenium

  77. Which of the following is the most resilient way to locate a login button that lacks a unique ID?

    • Use an absolute XPath starting from the root of the document
    • Use a CSS selector based on the button's index in the DOM tree
    • Use a relative XPath or CSS selector targeting an attribute like 'name' or a unique class
    • Use the tag name 'button' to find the first button on the page

    Answer: Use a relative XPath or CSS selector targeting an attribute like 'name' or a unique class. Using attributes like name or unique classes makes the selector resilient to structural changes. Absolute paths, index-based selectors, and generic tag names are fragile because they break whenever the page layout is rearranged.

    From lesson: Playwright vs Selenium

  78. What is the primary purpose of the 'driver.quit()' method compared to 'driver.close()'?

    • quit() closes only the currently focused window, while close() ends the session
    • quit() forces the browser to clear its cache and cookies immediately
    • quit() terminates the browser process and closes all open windows, while close() only closes one
    • quit() performs a soft logout of the application before closing the browser

    Answer: quit() terminates the browser process and closes all open windows, while close() only closes one. quit() is designed to clean up all windows and the driver instance itself, preventing memory leaks. close() is limited to the active handle. The other options describe functionalities that neither method performs.

    From lesson: Playwright vs Selenium

  79. Why is the Page Object Model (POM) design pattern recommended for test maintenance?

    • It increases the execution speed of individual test methods
    • It decouples the test logic from the underlying HTML structure, allowing for easier updates
    • It automatically generates reports after each test run
    • It eliminates the need for using synchronization methods like waits

    Answer: It decouples the test logic from the underlying HTML structure, allowing for easier updates. POM encapsulates page details, so when the UI changes, you update the Page Object once rather than in every test file. The other options are incorrect because POM does not affect execution speed, generate reports, or remove the need for synchronization.

    From lesson: Playwright vs Selenium

  80. If you encounter an ElementNotInteractableException, what is the most likely cause?

    • The element exists in the DOM but is currently hidden or covered by another element
    • The browser driver is out of date and needs an update
    • The test script is running on a machine with insufficient RAM
    • The application has blocked the automation tool's connection

    Answer: The element exists in the DOM but is currently hidden or covered by another element. This exception usually triggers when an element is found by the locator but cannot be clicked or typed into because it is obscured. Driver updates, RAM issues, or network blocks are unrelated to this specific DOM-interaction error.

    From lesson: Playwright vs Selenium

  81. Why is it recommended to use a fixture with the scope set to 'session' for initializing the WebDriver in pytest?

    • To allow the driver to be used by multiple threads simultaneously without collisions.
    • To ensure the browser only launches once for the entire test suite, improving execution speed.
    • To force the driver to reset its cookies and cache before every single test case.
    • To ensure that the browser is always opened in headless mode regardless of configurations.

    Answer: To ensure the browser only launches once for the entire test suite, improving execution speed.. Session scope ensures the driver is initialized once per suite run, which significantly reduces the overhead of browser startup times. Option 0 is incorrect as drivers are not thread-safe. Option 2 is false as session scope persists state. Option 3 is unrelated to the scope.

    From lesson: Selenium with pytest Integration

  82. What is the primary benefit of using 'yield' in a pytest fixture for Selenium?

    • It increases the priority of the test execution in the queue.
    • It allows the fixture to perform setup before the test and teardown after the test.
    • It forces the browser to run in a protected memory sandbox.
    • It automatically takes a screenshot if the test fails during execution.

    Answer: It allows the fixture to perform setup before the test and teardown after the test.. The yield keyword creates a generator fixture where the code before yield runs as setup, and code after yield runs as teardown (e.g., driver.quit()). Options 0, 2, and 3 describe functionalities not provided by the yield keyword itself.

    From lesson: Selenium with pytest Integration

  83. If a test fails because an element is not yet interactable, what is the most robust approach to fix the test?

    • Increase the hardcoded sleep duration until the element appears.
    • Use a try-except block to ignore the NoSuchElementException.
    • Implement a WebDriverWait using ExpectedConditions to poll for the element's state.
    • Switch the browser to a different driver instance to refresh the DOM.

    Answer: Implement a WebDriverWait using ExpectedConditions to poll for the element's state.. WebDriverWait polls the DOM and waits until the specific condition is met, making the test dynamic and fast. Hardcoded sleeps (Option 0) are brittle, ignoring errors (Option 1) hides bugs, and switching drivers (Option 3) does not fix synchronization.

    From lesson: Selenium with pytest Integration

  84. In the Page Object Model pattern, where should the 'driver.find_element' logic reside?

    • Directly inside the test file to maintain simple script readability.
    • Inside a helper class that contains all utility methods and constants.
    • Within the Page Object classes to encapsulate the interaction logic.
    • Inside the conftest.py file as a global variable for all tests.

    Answer: Within the Page Object classes to encapsulate the interaction logic.. Page Objects should encapsulate page-specific locators and interactions to keep the test code clean and maintainable. Option 0 creates tight coupling, Option 1 is too generic, and Option 3 is bad practice for global state.

    From lesson: Selenium with pytest Integration

  85. How does the 'pytest-xdist' plugin affect Selenium test execution?

    • It forces all tests to execute in a single sequential block.
    • It allows tests to be executed in parallel, potentially reducing total suite run time.
    • It automatically records a video of the browser interaction for every test.
    • It converts Selenium-based tests into API-based requests to improve speed.

    Answer: It allows tests to be executed in parallel, potentially reducing total suite run time.. xdist enables parallel test execution. Sequential execution (Option 0) is the default without plugins. Option 2 describes a reporting tool, not xdist, and Option 3 is technically incorrect as xdist does not change the nature of the Selenium protocol.

    From lesson: Selenium with pytest Integration

  86. If a test fails with a StaleElementReferenceException, what is the most likely cause?

    • The element was not found in the DOM at all.
    • The element's properties changed or the DOM refreshed after the reference was stored.
    • The browser driver is incompatible with the browser version.
    • The locator strategy used is too generic.

    Answer: The element's properties changed or the DOM refreshed after the reference was stored.. StaleElementReferenceException occurs when an element is no longer attached to the DOM, often due to page refreshes or dynamic updates. Option 0 is a NoSuchElementException, Option 2 is a Driver issue, and Option 3 is a locator quality issue.

    From lesson: Selenium Interview Questions

  87. Which strategy is most effective for handling dynamic web elements that frequently change their hierarchy?

    • Absolute XPath
    • Absolute CSS Selectors
    • Relative CSS Selectors using stable attributes
    • Index-based child selection

    Answer: Relative CSS Selectors using stable attributes. Relative CSS selectors using stable attributes (like ID or custom data tags) are immune to structural changes. The others rely on the hierarchy or position, which are prone to breaking when layout updates occur.

    From lesson: Selenium Interview Questions

  88. What is the primary difference between driver.close() and driver.quit()?

    • close() kills all processes; quit() only kills the active one.
    • close() closes the current window; quit() closes all windows and ends the session.
    • quit() is for headless mode; close() is for GUI mode.
    • There is no functional difference between the two.

    Answer: close() closes the current window; quit() closes all windows and ends the session.. driver.close() closes the specific window currently in focus, whereas quit() closes all open windows associated with the session and cleans up the driver instance. The others are incorrect descriptions of their scope.

    From lesson: Selenium Interview Questions

  89. When should an Implicit Wait be preferred over an Explicit Wait?

    • When you need to wait for a specific condition like invisibility.
    • When you need to wait for a specific element to be clickable.
    • When you want a global timeout applied to all findElement calls throughout the script.
    • It should never be preferred over Explicit Waits.

    Answer: When you want a global timeout applied to all findElement calls throughout the script.. Implicit waits are global settings for the driver instance to wait for a specific duration. Explicit waits (WebDriverWait) are preferred for specific conditions (Options 0 and 1), but option 2 correctly identifies the intended use case of global configuration.

    From lesson: Selenium Interview Questions

  90. Why is it discouraged to mix Implicit and Explicit waits in the same test script?

    • It causes the browser to crash immediately.
    • It can lead to unpredictable wait times and timeouts, causing intermittent test failure.
    • It consumes twice as much memory during execution.
    • The code will fail to compile.

    Answer: It can lead to unpredictable wait times and timeouts, causing intermittent test failure.. Mixing these wait types causes the driver to wait for both, often leading to unpredictable total wait times that exceed expected thresholds. It does not cause crashes or compile errors, and it does not impact memory.

    From lesson: Selenium Interview Questions