0% found this document useful (0 votes)
7 views12 pages

Selenium MCQs

The document provides an overview of Selenium and its associated tools, including Swagger products, testing frameworks like JUnit, Cucumber, Appium, and TestNG, and various Selenium features such as assertions, waits, and commands. It also discusses the evolution of Selenium, its compatibility with multiple programming languages, and best practices for UI testing. Additionally, it addresses common questions regarding Selenium's capabilities, architecture, and comparisons with other testing tools.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views12 pages

Selenium MCQs

The document provides an overview of Selenium and its associated tools, including Swagger products, testing frameworks like JUnit, Cucumber, Appium, and TestNG, and various Selenium features such as assertions, waits, and commands. It also discusses the evolution of Selenium, its compatibility with multiple programming languages, and best practices for UI testing. Additionally, it addresses common questions regarding Selenium's capabilities, architecture, and comparisons with other testing tools.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 12

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

Testing Frameworks and Tools


1. JUnit

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:

• Annotations like @Test, @Before, @After, etc.


• Assertions for validating test results.
• Supports test runners and parameterized tests.

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:

• Uses Gherkin syntax (Given-When-Then) to define test cases.


• Supports integration with JUnit and TestNG.
• Can be used for UI, API, or functional testing.

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:

• Works with multiple programming languages (Java, Python, etc.).


• Uses WebDriver protocol (like Selenium).
• Cross-platform support.

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:

• Annotations like @Test, @BeforeSuite, @AfterSuite.


• Supports parallel test execution.
• Provides better control over test execution flow.

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

Assertions in Selenium IDE


Assertions in Selenium IDE are used to validate expected vs. actual results. The available types of assertions
in Selenium IDE include:

• Assert → Hard assertion; test stops if it fails.


• Verify → Soft assertion; test continues even if it fails.
• WaitFor → Ensures that an element is present before proceeding.

Swagger Open API


Feature OpenAPI 2.0 OpenAPI 3.0
Version Identifier swagger: "2.0" openapi: "3.0.0"

Schema Definitions definitions components/schemas

Request Body Defined in parameters Uses requestBody


Multiple Response Types Limited Fully supported
Callbacks (WebSockets, Events) No support Supported
Multiple Servers Not supported Supported

Window Handle in Selenium


Syntax
1. get.windowhandle(): This method helps to get the window handle of the current window
2. get.windowhandles(): This method helps to get the handles of all the windows opened
3. set: This method helps to set the window handles in the form of a string. set<string> set=
driver.get.windowhandles()
4. switch to: This method helps to switch between the windows
5. action: This method helps to perform certain actions on the windows

Selenium Waits / Synchronization Mechanisms

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:

Wait<WebDriver> wait = new FluentWait<>(driver)


.withTimeout(Duration.ofSeconds(30))
.pollingEvery(Duration.ofSeconds(5))
.ignoring(NoSuchElementException.class);

WebElement element = wait.until(driver -> driver.findElement(By.id("myId")));

Quick Comparison:

Wait Type Scope Use Case Customizable?


implicitlyWait() All element searches General delays in element availability
pageLoadTimeout() Whole page load Slow-loading full pages
setScriptTimeout() JS script execution Waiting for JavaScript/AJAX completion
FluentWait Specific conditions Dynamic or flaky elements
1. Question: Who developed Selenium and in what year?
Answer: Jason Huggins developed Selenium in 2004.
Note: Selenium started as an internal tool at ThoughtWorks.

2. Question: Name a few programming languages supported by Selenium.


Answer: Selenium supports Java, Python, C#, Ruby, JavaScript (Node.js), PHP, and Perl.
Note: This multi-language support makes Selenium versatile for different development
environments.

3. Question: Is Selenium compatible with only Windows operating systems?


Answer: No, Selenium is cross-platform and works on Windows, macOS, and Linux.
Note: Its platform independence is a key advantage.

4. Question: What defines open-source software?


Answer: Open-source software is freely available, and its source code can be modified and
distributed by anyone.
Note: This fosters community contribution and transparency.

5. Question: What aspects of a software application does UI testing cover?


Answer: UI testing covers the visual elements and user interactions, including font, color, layout,
and functionality that users directly engage with.
Note: It ensures a positive user experience.

6. Question: Name a few alternatives to Selenium for UI testing.


Answer: Alternatives include Cucumber, Cypress, and Playwright.
Note: Each alternative has its own strengths and weaknesses.

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.

11. Question: Briefly describe the evolution of Selenium from version 1 to 3.


Answer: Selenium evolved from Selenium RC (version 1), which had a client-server architecture, to
Selenium WebDriver (version 3), which offers direct browser interaction and improved performance.
Selenium Grid was developed to run tests in parallel across different environments.
Note: The architecture shifted significantly to improve efficiency and flexibility.

1. Question: Name the four core components of Selenium.


Answer: Selenium IDE, Selenium RC, Selenium WebDriver, and Selenium Grid.
Note: Understanding these components is fundamental to using Selenium effectively.

2. Question: What is the primary function of Selenium commands?


Answer: Selenium commands (also known as Selenese in Selenium IDE) instruct the browser to
perform specific actions, such as navigating to a URL, locating elements, and interacting with them.
Note: These commands are the building blocks of test scripts.

3. Question: Briefly explain the architecture of Selenium WebDriver.


Answer: Selenium WebDriver uses a direct communication approach where the test script interacts
with browser-specific drivers (e.g., ChromeDriver, GeckoDriver). These drivers then control the
browser without the need for an intermediary server.
Note: This direct communication makes it faster and more stable than Selenium RC.

4. Question: What is the difference between findElement() and findElements() in Selenium?


Answer: findElement() returns the first matching element located by the specified locator. If no
element is found, it throws a NoSuchElementException. findElements() returns a list of all matching
elements. If no elements are found, it returns an empty list.
Note: Choose the appropriate method based on whether you expect one or multiple elements.
5. Question: Name a few common types of locators used in Selenium to identify web elements.
Answer: Common locators include ID, name, class name, tag name, link text, partial link text, CSS
selector, and XPath.
Note: Selecting the right locator strategy is crucial for robust test scripts.

1. Question: List the four components of the Selenium suite.


Answer: Selenium IDE, Selenium RC, Selenium WebDriver, and Selenium Grid.
Note: Reinforcing the core components.

2. Question: What was the primary purpose of Selenium IDE?


Answer: Selenium IDE was primarily designed as a record-and-playback tool to quickly create
simple test scripts, mainly for prototyping and learning.
Note: It has limitations for complex scenarios.

3. Question: What is Maven typically used for in a Selenium project?


Answer: Maven is a build automation tool used for managing project dependencies (like Selenium
libraries), building the project, running tests, and generating reports.
Note: It helps in organizing and managing Java-based Selenium projects.

4. Question: Why is exception handling important in test automation scripts?


Answer: Exception handling allows test scripts to gracefully handle unexpected errors during
execution (e.g., element not found) without abruptly stopping, making the tests more robust and
providing informative failure reports.
Note: It improves the reliability and maintainability of tests.

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.

1. Question: On which browser was Selenium IDE initially available as an extension?


Answer: Selenium IDE was initially available as a Firefox browser extension.
Note: It has since been re-released as a cross-browser extension.

2. Question: Give examples of WebDriver commands used in Selenium.


Answer: Examples include driver.get("url"), driver.findElement(By.id("elementId")).click(),
driver.findElement(By.name("inputName")).sendKeys("text"), driver.getTitle(), and driver.close().
Note: These commands are the actions you tell the browser to perform.

3. Question: Name a few programming languages supported by Selenium WebDriver.


Answer: Java, Python, C#, Ruby, JavaScript (Node.js), PHP, and Perl.
Note: WebDriver maintains the multi-language support.

4. Question: What is TestNG commonly used for in Selenium?


Answer: TestNG is a testing framework for Java that provides features like test annotations, test
grouping, parameterization, and report generation, enhancing the organization and execution of
Selenium tests.
Note: It's a popular choice for structuring Java-based Selenium projects.

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.

3. Question: Is Selenium typically used for testing Flex applications?


Answer: Selenium has historically had challenges with Flex applications. Specialized tools or
libraries might be more suitable for testing Flex UIs.
Note: Selenium's strength lies in testing standard web technologies.
4. Question: What was the original name of Selenium IDE?
Answer: The original name of Selenium IDE was "Selenium Recorder".
Note: This reflects its initial record-and-playback functionality.

5. Question: Are all WebDriver features supported by Selenium IDE?


Answer: No, Selenium IDE has limitations compared to WebDriver. It may not support all the
advanced interactions and browser configurations available in WebDriver.
Note: WebDriver offers greater flexibility and control.

6. Question: Name an example of an "Expected Condition" that is not specific to WebDriver.


Answer: While "Expected Conditions" are heavily used with WebDriver's explicit waits, a general
concept of an expected condition in testing could be something like a database record being created
after a UI action, which isn't directly a WebDriver condition. However, the question likely refers to
conditions used in Selenium's WebDriverWait.
Note: Expected conditions are crucial for robust synchronization in WebDriver.

7. Question: What were some significant changes introduced in Selenium 3.0?


Answer: A major change was the decoupling of the browser drivers, requiring them to be separate
executables. Also, the architecture shifted to a more W3C WebDriver compliant model.
Note: This improved standardization and browser compatibility.

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.

1. Question: What is the default implicit wait time in Selenium?


Answer: The default implicit wait time in Selenium is 0 seconds. You need to explicitly set it if you
want a different default.
Note: Implicit wait applies globally for the lifetime of the WebDriver instance.
2. Question: How can you delete browser cookies using Selenium?
Answer: You can use the driver.manage().deleteAllCookies() method to delete all cookies for the
current domain. You can also delete specific cookies using
driver.manage().deleteCookieNamed("cookieName") or
driver.manage().deleteCookie(cookieObject).
Note: Managing cookies can be important for testing different user sessions.

3. Question: What are different strategies for identifying web elements?


Answer: Using locators like ID, name, class name, tag name, link text, partial link text, CSS
selector, and XPath.
Note: Reinforces the core element identification techniques.

4. Question: Give examples of common Selenium commands.


Answer: get(), click(), sendKeys(), getText(), getAttribute(), findElement(), findElements(),
getTitle(), getCurrentUrl(), close(), quit().
Note: These are fundamental actions in Selenium automation.

5. Question: What are "entry criteria" in the context of testing?


Answer: Entry criteria define the prerequisites that must be met before testing can begin. This might
include having the application deployed, test data set up, and the environment configured correctly.
Note: Ensures that testing is performed under the right conditions.

6. Question: What is XPath and how is it used for locating elements?


Answer: XPath (XML Path Language) is a query language used to navigate through the XML
structure of an HTML document. In Selenium, By.xpath("your_xpath_expression") is used to locate
elements based on their position and attributes in the DOM.
Note: XPath is powerful for complex element location but can be less readable and potentially less
performant than CSS selectors for simpler cases.

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.

11. Question: What is Selenium Hub and what is its purpose?


Answer: Selenium Hub is the central point in Selenium Grid. It receives test requests and distributes
them to available Selenium Nodes (browser instances on different machines or VMs), enabling
parallel test execution across various browsers and operating systems.
Note: Essential for scaling test automation efforts.

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

You might also like