Selenium MCQs
Selenium MCQs
Swagger’s Products:
1. A browser-based editor where OpenAPI specifications can be written – Swagger Editor
2. Produces client libraries for our API in more than 40 different languages. – Swagger codegen
3. Produces interactive API documentation. – Swagger UI
JUnit is a Java-based testing framework used for unit testing. It is widely used for testing individual
components of an application in isolation.
Key Features:
2. Cucumber
Cucumber is a Behavior-Driven Development (BDD) testing framework that allows writing test cases in
plain English (Gherkin syntax), making it easier for non-technical stakeholders to understand.
Key Features:
3. Appium
Appium is an open-source test automation tool for mobile applications (iOS and Android). It supports
native, hybrid, and web applications.
Key Features:
4. TestNG
TestNG (Test Next Generation) is a testing framework inspired by JUnit but with additional features like
parallel execution, dependency management, and data-driven testing.
Key Features:
Differences:
Feature JUnit Cucumber Appium TestNG
Type Unit Testing BDD Mobile Test Test Framework
Framework Framework Automation
Syntax Java-based test Gherkin (Given- Uses WebDriver Java-based test cases
cases When-Then) API
Use Case Unit testing BDD testing Mobile Unit/Functional/Integration
automation testing
Parallel No No Yes Yes
Execution
Integration Works with Works with Works with Works with Selenium,
Cucumber, JUnit, TestNG Selenium, Cucumber
TestNG TestNG
1. implicitlyWait()
• Purpose: Sets a default wait time for the WebDriver to look for elements.
• Applies To: All elements.
• Use Case: When elements may appear slowly but are generally always present.
• Example:
• driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
2. pageLoadTimeout()
• Purpose: Sets the maximum time to wait for a full web page to load.
• Use Case: When pages sometimes take longer than expected to load.
• Example:
driver.manage().timeouts().pageLoadTimeout(Duration.ofSeconds(30));
3. setScriptTimeout()
• Purpose: Sets the maximum time to wait for asynchronous JavaScript scripts to execute.
• Use Case: Useful for apps heavily reliant on JS (e.g., AJAX).
• Example:
driver.manage().timeouts().scriptTimeout(Duration.ofSeconds(20));
4. FluentWait()
• Purpose: Waits for a specific condition with custom polling intervals and exception handling.
• Use Case: When elements load unpredictably or intermittently.
• Features:
o Custom timeout
o Polling interval
o Exception ignoring
• Example:
Quick Comparison:
7. Question: Is Mocha considered an alternative to Selenium for UI testing? Why or why not?
Answer: No, Mocha is primarily a JavaScript test framework used for unit and integration testing of
JavaScript applications, not specifically for UI testing in the same way as Selenium or Cypress.
Note: Mocha often works with UI testing tools but isn't a direct alternative.
8. Question: What is a key characteristic of Selenium WebDriver that was introduced in Selenium 3.0
regarding server installation?
Answer: Selenium WebDriver, from version 3.0 onwards, does not require a separate server
installation to interact with browsers directly.
Note: This simplified the architecture compared to Selenium RC (version 1).
9. Question: How does Selenium compare to QTP (now UFT) in terms of licensing?
Answer: Selenium is open-source and free to use, whereas QTP/UFT is a commercial tool that
requires a license.
Note: Cost is a significant differentiator.
10. Question: What are the four main components of the Selenium suite?
Answer: The four main components are Selenium IDE, Selenium RC (Remote Control), Selenium
WebDriver, and Selenium Grid.
Note: Each component serves a different purpose in test automation.
5. Question: Name some programming languages that are officially supported by Selenium.
Answer: Java, Python, C#, Ruby, JavaScript (Node.js), PHP, and Perl.
Note: Emphasizing the language flexibility again.
5. Question: What are the different strategies or methods to identify web elements on a page?
Answer: Strategies include using locators like ID, name, class name, tag name, link text, partial link
text, CSS selector, and XPath.
Note: Choosing the best strategy depends on the element and the stability of its attributes.
6. Question: What are regular expressions and how might they be useful in Selenium?
Answer: Regular expressions are patterns used for matching character combinations in strings. In
Selenium, they can be useful for locating elements with dynamic or partially known attributes (e.g.,
IDs that change slightly).
Note: They add flexibility to element identification.
1. Question: What are different ways to locate elements on a web page using Selenium?
Answer: Using various locators such as ID, name, class name, tag name, link text, partial link text,
CSS selector, and XPath.
Note: Reinforces the importance of locator strategies.
2. Question: How can you store values or data within your Selenium scripts?
Answer: You can use variables in the programming language you are using with Selenium (e.g.,
Python variables, Java variables) to store values like element text, URLs, or test data.
Note: Proper data management is essential for maintainable tests.
3. Question: How can Selenium be used to automate testing across multiple web browsers?
Answer: Selenium WebDriver supports different browser drivers (e.g., ChromeDriver for Chrome,
GeckoDriver for Firefox, EdgeDriver for Edge). By instantiating the appropriate driver, you can run
the same test scripts on different browsers.
Note: Cross-browser compatibility testing is a key strength of Selenium.
4. Question: How can you identify elements that share the same HTML class attribute?
Answer: You can use the By.className() locator or, more powerfully, CSS selectors (.className) or
XPath expressions that target elements with that specific class.
findElements(By.className("sharedClass")) will return a list of all such elements.
Note: Class names are often used for styling and can be shared by multiple elements.
5. Question: What are CSS selectors and how are they used in Selenium?
Answer: CSS selectors are patterns used to select HTML elements based on their tags, attributes,
and relationships in the document structure. Selenium uses By.cssSelector("your_selector") to locate
elements matching these patterns.
Note: CSS selectors are often more concise and performant than XPath for simple selections.
6. Question: How can you verify if a specific element is selected on a web page?
Answer: You can use the isSelected() method on a WebElement (e.g., for checkboxes or radio
buttons) to check if it is currently selected.
Note: This is important for verifying the state of interactive elements.
7. Question: How can you execute multiple test cases or test suites in Selenium?
Answer: This depends on the testing framework being used (e.g., TestNG, JUnit, pytest). These
frameworks provide mechanisms to group tests into suites and run them sequentially or in parallel.
Note: Efficient test execution is crucial for larger test projects.
1. Question: How can you retrieve text or other content from specific HTML tags using Selenium?
Answer: You can use methods like getText() to retrieve the visible text content of an element, or
getAttribute("attributeName") to get the value of a specific HTML attribute.
Note: Essential for verifying dynamic content and element properties.
2. Question: What kind of validations might you perform on the appearance of a button using
Selenium?
Answer: You might validate its text, color (using CSS properties), size, position, whether it's enabled
or disabled, and other visual attributes.
Note: Ensures the UI looks and behaves as expected.
8. Question: How can you instruct FluentWait to ignore specific types of exceptions?
Answer: You can use the ignoring(ExceptionClass.class) method of the FluentWait object to specify
exceptions that should be ignored during the waiting process.
Note: This prevents the wait from failing immediately due to expected, temporary exceptions.
9. Question: How can you select an option from a dropdown list using its index?
Answer: You can use the Select class in Selenium WebDriver. After creating a Select object for the
dropdown element, you can use the selectByIndex(index) method (where index is a zero-based
integer).
Note: Index-based selection can be useful but might be less robust if the order of options changes.
7. Question: What are "methods" in programming and how are they used in Selenium?
Answer: Methods (or functions) are blocks of reusable code that perform specific tasks. In
Selenium, WebDriver provides various methods (like click(), sendKeys()) to interact with web
elements and the browser. You also create your own methods to organize your test logic.
Note: Methods promote code reusability and organization.
8. Question: How can regular expressions be used in Selenium for element identification?
Answer: You can use regular expressions within XPath or CSS selectors to match elements based on
patterns in their attributes or text. For example, //*[contains(text(), 'Part')] in XPath would find
elements containing the text "Part".
Note: Useful for handling dynamic content or attributes.
9. Question: Can you execute JavaScript within the browser using Selenium?
Answer: Yes, Selenium WebDriver provides the JavascriptExecutor interface, which allows you to
execute JavaScript code in the context of the current browser window.
Note: Useful for performing actions that are not directly supported by WebDriver commands or for
interacting with complex UI elements.
10. Question: What are dynamic IDs and how can you handle them in Selenium?
Answer: Dynamic IDs are element identifiers that change each time the page loads, making them
unreliable for direct use in Selenium locators. You can handle them by using more stable attributes
like name, class name, or by constructing XPath or CSS selectors that target other unique and
consistent properties or relationships.
Note: A common challenge in web automation.
12. Question: What are some ways to validate the appearance or state of a button?
Answer: By checking its text, CSS properties (color, background), size, position, whether it's
enabled/disabled, and potentially its displayed icon or other visual cues.
Note: Ensures the button renders and behaves correctly.
13. Question: Is Selenium fully compatible with all CSS versions and features?
Answer: Selenium interacts with the browser's rendering engine, so its compatibility with CSS
depends on the capabilities of the specific browser being used for testing. Generally, it supports
widely adopted CSS