Selenium Interview Questions
Selenium Interview Questions
Selenium Interview Questions
Selenium is one of the most popular automated testing suites. Selenium is designed in a way to support
and encourage automation testing of functional aspects of web-based applications and a wide range of
browsers and platforms
Selenium is one of the most popular open source free licensed automation tool for web applications
Selenium Integrated Development Environment (IDE) – Selenium IDE is a record and playback
tool. It is applicable only for Firefox Plugin.
Selenium Remote Control (RC) – Selenium RC is a server that allows a user to create test scripts
in the desired programming language. It also allows executing test scripts within the large
spectrum of browsers.
Selenium Web Driver – Web Driver is a different tool altogether that has various advantages
over Selenium RC. Web Driver directly communicates with the web browser and uses its native
compatibility to automate.
Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms
and environments concurrently.
The locator can be termed as an address that identifies a web element uniquely within the webpage. we
have different types of locators in Selenium:
ID
ClassName
Name
TagName
LinkText
PartialLinkText
Xpath
CSS Selector
DOM
Single Slash “/” – Single slash is used to create Xpath with absolute path i.e. the xpath would be created
to start selection from the document node/start node.
Double Slash “//” – Double slash is used to create Xpath with relative path i.e. the xpath would be
created to start selection from anywhere within the document.
The values of the css properties can be retrieved using a get () method:
Syntax:
driver.findElement (By.id (“id“)).getCssValue (“name of css attribute”);
driver.findElement (By.id (“id“)).getCssValue (“font-size”);
//input[@id=’name’]//following-sibling::label
Sample code:
driver.navigate ().back ();
navigate ().forward () – This command lets the user to navigate to the next web page with reference to
the browser’s history.
Sample code:
driver.navigate ().forward ();
navigate ().refresh () – This command lets the user to refresh the current web page there by reloading all
the web elements.
Sample code:
driver.navigate ().refresh ();
navigate ().to () – This command lets the user to launch a new web browser window and navigate to the
specified URL.
Sample code:
driver.navigate ().to (“https://google.com”);
close (): Web Driver’s close () method closes the web browser window that the user is currently working
on or we can also say the window that is being currently accessed by the WebDriver. The command
neither requires any parameter nor does is return any value.
quit (): Unlike close () method, quit () method closes down all the windows that the program has
opened. Same as close () method, the command neither requires any parameter nor does return any
value
WebDriver provides an Actions class for performing mouse actions like click, double click, right-click,
drag and drop, etc. You can use it like this:
actions.click(element).perform();
11. What is the Page Object Model (POM), and why is it useful in Selenium WebDriver?
The Page Object Model is a design pattern that represents each web page as a Java class and stores the
locators and methods related to that page within the class. It promotes code reusability, maintainability,
and reduces code duplication in test scripts.
12. What is the PageFactory pattern, and how does it improve the Page Object Model (POM)?
The PageFactory pattern is used to initialize elements defined in a Page Object class. It improves the
POM by simplifying element initialization and making the code more readable and maintainable.
13. How do you handle dynamic elements or elements with changing attributes in Selenium WebDriver?
You can use dynamic XPath or CSS selectors that are based on the common, unchanging parts of the
element's attributes, or you can use relative XPath expressions to locate elements based on their
relationship to other elements.
WebDriver is the interface used to interact with the web browser, while WebElement represents an
HTML element on a web page. WebDriver is responsible for navigating, managing the browser, and
locating web elements, whereas WebElement is used to interact with those elements.
TestNG is a testing framework for Java that simplifies test case management and allows parallel test
execution, grouping, and reporting. It is often used in conjunction with Selenium for test automation.
`getText()` is used to retrieve the visible text of an element, while `getAttribute()` is used to retrieve the
value of an element's attribute.
You can capture screenshots using the `TakesScreenshot` interface and saving the screenshot to a file.
You can manage cookies using the `getCookies()`, `addCookie()`, and `deleteCookieNamed()` methods in
Selenium WebDriver.
`getWindowHandle()` returns the handle of the current window, while `getWindowHandles()` returns
a set of handles for all open windows. This is useful for switching between windows or tabs
DesiredCapabilities are used to specify the desired browser and platform configurations when working
with Selenium Grid.
21. What are the common exceptions in Selenium WebDriver and how can you handle them?
You can handle pop-up windows using the `Alert` class methods in Selenium WebDriver.
*Requirement
*Feasibility
*Design
*Coding
*Testing
*Installation
*Maintance
*System Study
*Test plan
*Test document
*R.T.M document
*Test Execution
*Defect tracking
*Retrospect/Postman meeting
TestNG is a testing framework for Java that simplifies test case management and allows parallel test
execution, grouping, and reporting. It is often used in conjunction with Selenium for test automation.
TestNG annotations are used to control the flow and execution of test cases. Annotations like `@Test`,
`@BeforeSuite`, `@AfterMethod`, etc., are used to specify test methods, setup, and teardown methods.
Smoke Testing.
Sanity Testing.
UI Testing.
Database Testing.
Cross Browser Testing.
Regression Testing.
*look into source code and test the logic of the code