Top 100+ Selenium Interview Questions and Answers: Updated On Jun 7, 2023 15:02 IST
Top 100+ Selenium Interview Questions and Answers: Updated On Jun 7, 2023 15:02 IST
Shiksha Online
Updated on Jun 7, 2023 15:02 IST
Selenium is an open-source application that is used to automate web browsers
across the platforms and caters to different testing requirements.
In this article we will covers 100+ Selenium interview questions that leaves no scope
of doubt once you give it a thorough read.
Selenium is a suite of tools to automate web browsers across many platf orms. It is a f ree,
open-sourced application that caters to dif f erent testing requirements. It supports the
authoring of tests without having to learn a scripting language and provides a domain-
specif ic language to write tests in many popular programming languages. T he tests written
on Selenium can be run on most modern web browsers. Due to these advantages, Selenium
has become popular in the automation testing domain. If you are preparing f or a Selenium
interview, here are the top f requently asked Selenium interview questions and answers to
boost your interview preparation.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Top Selenium Interview Questions and Answers:
Here are the most important Selenium interview questions f or f reshers and experienced
candidates.
Ans. Selenium support various programming languages such as C#, Java, PHP, Ruby,
Python, Perl, Javascript, etc.
Ans. Automation testing or T est Automation is a process of automating the manual process
to test the application/system under test.
T est Execution
Maintenance
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Q3. What are the dif f erent ways to f ind an element?
ID
Name
T ag
Attribute
CSS
Linktext
PartialLink T ext
X-path
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Must Check: Free Selenium Course and Certif icates
Functional T esting
Regression T esting
Sanity T esting
Smoke T esting
Responsive T esting
Integration T esting
Q5. What is the dif f erence between implicit wait and explicit wait in
selenium WebDriver?
Ans. When an implicit wait is implemented in tests, if WebDriver cannot f ind an element in the
Document Object Model (DOM), it will wait f or a def ined amount of time f or the element to
appear in the DOM.
An explicit wait can be used where synchronization is needed, f or example, the page is
loaded but we are still waiting f or a call to complete and an element to appear.
Ans. Explicit waits are better than implicit wait. Unlike an implicit wait, you can write custom
code or conditions f or wait bef ore proceeding f urther in the code.
Ans. Selenium IDE is the simplest of all the tools in the package and should be a great tool
f or naïve users as it is easy to learn with minimal acquaintances in the programming
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
language.
Q8. Explain the dif f erence between single (/) and a double slash (//)
in X-path?
Ans. Single slash (/) allows the creation of ‘absolute’ path expressions, while double slash
(//) allows the creation of ‘relative’ path expressions.
Ans. XPath is used to f ind the WebElement in web pages. It is also usef ul in identif ying the
dynamic elements.
Syntax:
Xpath=//tagname[@attribute=’value’]
@ : T o select attribute
Q10. What is the dif f erence between type keys and type
commands?
Ans. T ype key populates the value attribute using JavaScript whereas type commands
emulate actual user typing.
Q11. What is the dif f erence between verif y and assert commands?
Ans. Assert command allows us to check whether an element is on the page or not. Verif y
command checks whether the element is on the page, otherwise, the test will carry on
executing.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Q12. What are heightened privilege browsers?
Ans. Heightened privileges browsers are similar to Proxy Injection, allowing websites to do
something that is not commonly permitted.
Ans. In a Data-driven f ramework, the test data is separated and kept outside the T est
Scripts, while test case logic resides in T est Scripts.
Ans. Object repository is an essential entity in any UI automation that allows a tester to
store all objects that will be used in the scripts in one or more centralized locations rather
than scattered all over the test scripts.
Q17. How to f ind more than one web element in the list?
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
List <WebElement> elementList =
driver.f indElements(By.xpath(“//div[@id=’example’]//ul//li”));
Ans. Close() method closes the web browser window that the user is currently working on or
the browser that WebDriver is currently accessing.
Quit() method closes down all the windows that the program has opened.
Q19. In which f ormat does the source view show your script in
Selenium IDE?
Ans. XML
Ans. Object Repository is a term used to ref er to the collection of web elements belonging
to Application Under T est (AUT ) along with their locator values.
In Selenium, objects can be stored in an excel sheet that can be populated inside the script
whenever required.
Ans. T o navigate to a new window f rom the current window, you can use:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
driver.navigate().to(new window url) method
Q22. How can you convert any Selenium IDE tests f rom Selenese to
another language?
Ans. T he f ormat option of Selenium IDE to convert tests into another programming
language
Q24. What are the ways you can customize the TestNG report?’
A startpoint indicates the point f rom where the execution should begin.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
debugging of f unctional tests. T o create an advanced f ramework, Selenium IDE has to be
combined with Selenium WebDriver or Selenium Remote Control (RC).
It is a server that allows users to write test scripts in multiple programming languages and
browsers which results in better integration of Selenium in existing unit test f rameworks. It
accepts the commands f rom the test script and sends them to the browser as Selenium core
JavaScript commands. T he browser then behaves accordingly.
Selenium WebDriver
It is a tool that helps create and run test cases. It supports various platf orms like Windows,
Mac, and Linux and several browsers like Chrome, IE, Saf ari, and Firef ox. T he WebDriver can
be written on languages like Java, Python, C#, Ruby. It overcomes the disadvantages of
Selenium RC as it does not require an additional server and communicates natively with the
browser and runs on it.
Grid
Selenium Grid is a server that allows tests to use web browser instances running on remote
machines. Grid is exceptionally f lexible and is integrated with other suite components f or
simultaneous execution or parallel execution. It works with Selenium RC to run test cases
concurrently in multiple machines, browsers, and platf orms.
Q27. Can you tell f rom where the term Selenium derived?
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. Well, it came f rom a joke made by Jason Huggins (the developer of Selenium) in an
email, where he mocked one of his competitors named Mercury, saying that you can cure
mercury poisoning by taking selenium supplements. T his is f rom where the other email
recipients took the name and the rest is history.
Learn about software testing, read our blog – what is Software Testing?
Ans. Selenium is a f ree and open-source tool and has a large user base. It helps
communities and is compatible with every browser (Chrome, Firef ox, Internet Explorer, etc.).
Besides, it also has great platf orm compatibility (Windows, Mac OS, Linux, etc.)
Ans. Selenese is a set of selenium commands which are used f or testing a web application.
It is the language used f or writing test scripts in Selenium IDE. Using Selenese, a tester can
test the broken links, Ajax f unctionality, Alerts, window, list options, etc.
Actions:
T hese are the commands that interact directly with web applications. T hey change the state
of the application, such as click on some link, select a value f rom the drop-down, etc. For
example: Click and DoubleClick.
Accessors:
T hese commands check the state of the application and store the application state in a
user-def ined variable. For example: storeT itle and storeT extPresent.
Assertions:
T hese commands check the state of application against the expected conditions. T hey add a
checkpoint or verif ication in the automation tests. T here are three modes in assertions,
namely verif y, assert and waitf or. For example: assertT ext, assertT itle, verif yT ext, and
verif yT itle.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Q30. What is the dif f erence between automation testing and manual
testing?
Ans. The difference between automation testing and manual testing is:
Automated testing is f aster and reliable than Manual testing takes a lot of time and
manual testing. human ef f ort.
Ans. It uses a test suite to execute a batch f ile and also takes an executable f ile to set up
the process bef ore the automation. Below code can be used to initiate the process:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
batch.waitFor();
Ans. Selenium Grid sends tests to the hub, which are then redirected to Selenium Webdriver.
It then launches the browser and runs the test. T he tests run in parallel with the entire test
suite.
Ans. Yes, but it is not as ef f ective as Loadrunner, which is a dedicated Perf ormance T esting
tool.
Ans. Automation testing cannot f ully replace manual testing as it is not possible to expect
test automation to bring of f all the work done by manual testing.
Ans. Every object or control in a web page is an element in Selenium, and some of the ways
to f ind that element in a web page include user ID, Name, T ag, Attribute, CSS, Linktext,
PartialLink T ext, and Xpath.
Ans. Page Factory provides an optimized way to implement Page Object Model and it has a
very good memory utilization and implementation is object-oriented.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. XPath is a language that helps to locate and process items in Extensible Markup
Language (XML) documents. It addresses syntax based on a path through the document’s
logical structure or hierarchy. XPath is used to locate a web element based on its XML path. It
also stores, organizes, and transports arbitrary data.
Absolute XPath
Syntax: html/body/div[1]/section/div[1]/div/div/div/div[1]/div/div/div/div/div[3]/div[1]/div/h4[1]/b
Relative Xpath
Syntax:
Q40. How do we run the selenium IDE test suite f rom the command
line?
Ans. We can use the below command to run the test suite:
Syntax:
Q41. How can we perf orm drag and drop action in Selenium
WebDriver?
Ans. We can use the advanced user interaction API to perf orm drag and drop operations:
Example:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
act.dragAndDrop(source_locator, target_locator).build().perf orm();
Q42. Name the Selenese command that is used to present the value
of a variable?
Ans. echo() is the command used for presenting the variable value.
Ans. Since it is an automation testing tool and supports only web application testing, it can’t
handle windows pop up. However, third-party tools like AutoIT m and Robot class are
available to handle this.
Ans. We can use WebDriver, which provides an ef f icient way to handle these pop-ups using
the Alert interf ace. Besides, there are f our methods too that we can use –
void dismiss() – T he accept() method clicks on the “Cancel” button when the pop-up window
appears.
void accept() – T he accept() method clicks on the “Ok” button when the pop-up window
appears.
String getT ext() – T he getT ext() method returns the text displayed on the alert box.
void sendKeys(String stringT oSend) – T he sendKeys() method enters the specif ied string
pattern into the alert box.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Syntax:
Ans. You can do that by using the T akeScreenshot f unction and by using getScreenshotAs()
method, you can save the screenshot.
Ans. Yes, we can enter/ send a text using JavaScriptExecutor, and we don’t need to use
sendKeys() method.
JUnit Annotations help identif y the type of methods we have def ined in our test code.
Following are some of the common JUnit Annotations:
@Bef oreClass: It lets the system know that this method shall be invoked only once
bef ore any of the test methods.
@Bef ore: It denotes that the method shall be executed every time bef ore each of the test
methods.
@T est: It denotes that the method annotated as @T est is a test method. It does not
take any attributes. T here can be multiple test methods in a single test script.
@Af ter: It denotes that the method shall be executed every time af ter each of the test
methods.
@Af terClass: It tells the system that this method shall be executed once af ter any of the
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
test methods.
Some of the JUnit Annotations f or specif ic purposes are @ParameterizedT est, @RunWith,
@RepeatedT est, and @Parameters.
Ans. Object Repository ref ers to a collection of web elements belonging to Application
Under T est (AUT ) along with their locator values. Object Repository is used to store
locators in a centralized location.
Ans. We can create Object Repository in an excel sheet that can be populated inside the
script whenever required.
Android – Selendroid/Appium
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Firef ox – FireFoxDriver
IOS – ios-driver/Appium
Ans. Selenium WebDriver automates web applications using the browser’s native method.
T heref ore, it is not possible to test web services using Selenium WebDriver because they
are headless.
Ans. Absolute XPath locates an element using XML expression that starts f rom the root
node or with ‘/’. It contains the complete path of all the elements, including the root element,
as well as the desired element. Absolute XPath has a signif icant disadvantage, which is if
there is even a minor change in the UI, the entire XPath f ails.
Ans. Relative XPath locates an element using XML expression, beginning f rom anywhere in
the HT ML document. T his is used to create robust XPaths, which remain unaf f ected by
changes in other UI elements.
Ans. T o identif y a child element using XPath, we can use the below code:
Syntax: //div/a
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. T o identif y web elements by their class, we can use .className and select elements
belonging to that particular class. Apart f rom this, a CSS selector can locate web elements
with ID, class, or name.
Q57. How to use CSS Selector f or identif ying web elements by ID?
Ans. T o identif y web elements by ID, we can use #idValue and select elements belonging to
that particular ID.
Q58. How to use CSS Selector f or identif ying web elements by their
attribute value?
Ans. T o identif y web elements by their attribute value, we can use [attribute=value] to select
elements belonging to that particular attribute type.
Q59. How can we move to nth child element using the CSS
Selector?
Q60. Explain the dif f erence between XPath and CSS Selector.
Ans. In XPath, we can traverse both f orward and backward, while CSS selector moves
f orward only.
Ans. Your reply should be specif ic here. You should f ocus on how you automate test cases
to do Regression testing, Smoke testing, and Sanity testing. You can also mention that you
have done End to End testing, basis project, and test time estimation.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
How?
Ans. Yes, we can launch dif f erent browsers in Selenium WebDriver by creating an instance
of the driver of the particular browser.
T oggling a checkbox on/of f can also be done using the click() method, and isSelected()
method is used to check if the Checkbox is toggled on or of f .
Ans. driver.getWindowHandle() is a unique identif ier and it returns a handle of the current
page
alertIsPresent()
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
titleContains(String title)
titleIs(String title)
Ans. DesiredCapabilities are a set of key-value pairs that help to set properties f or the
WebDriver. T his helps to set the specif ic properties of browsers such as browser name,
platf orm, and version of the browser, in the browser instances.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Q70. What is Selenium 2.0, and how is it better than Selenium 1.0?
Ans. Selenium 1 is known as Selenium Remote Control (RC). Selenium 2.0 is a combination
of Selenium 1 and WebDriver, making it superior to RC. Selenium 2 is also popularly known
as Selenium WebDriver that directly sends commands to the browser instead of sending it to
a server. Selenium 2.0 runs the JavaScript natively; thus there is a need to write the test
once, and Selenium will test on dif f erent browsers.
Q71. What is Selenium 3.0, and how is it better than Selenium 2.0?
Ans. T here was a major WebDriver upgrade in 2016 and Selenium 3.0 incorporates that
upgrade, which includes the W3C specif ications f or Webdriver APIs.
Q72. How can we pass parameters to the test script using TestNG?
Ans. We can use Parameter annotation and Parameter tag in T estNG.xml to pass
parameters to the test script.
New T estNG.xml –
Q73. Can you explain how we can make two test methods dependent
on each other using TestNG?
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. T here is a f eature in T estNG, dependency, which allows a test method to depend on
other test methods. Dependency is conf igured by using the dependent test method
separated by commas to the attribute dependsOnMethods. T his is done while using test
annotation on multiple test methods.
Ans.“Type” command is used for entering keyboard key values into the text box of a
software web application. It is also used for choosing values from a combo box. On
the other hand, “typeAndWait” is used once you finish typing and when the software
web page begins to reload. This command waits for the software program page to
reload before proceeding. You will have to use the basic “type” command in case
there is no page reload event while typing.
Q75. What are the dif f erent OS/platf orms supported by Selenium?
Android
IOS
Linux
Mac OS X
Windows Desktop
Windows Mobile
Acceptance tests
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Cross-browser tests
Functional cases
Integration tests
Responsiveness cases
Sanity test
Smoke testing
By.name()
By.tagName()
By.className()
By.id()
By.linkT ext()
By.xpath
By.cssSelector()
By.partialLinkT ext()
Ans. T o iterate through options in the test script, you can use dif f erent test data and
activate a “f or” loop in the program
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
// test data collection in an array
Q79. What are the element locators that can be used to locate
elements on the web page in selenium IDE?
Ans. In Selenium, there are precisely f our locators that are used:
Html id
Html name
X-path locators
CSS locators
Ans. You can generate random numbers by using Java Script in Selenium IDE
type
css=input#s
javascript{Math.random()}
And f or
type
css=input#s
javascript{new Date()}
Ans. T o retrieve the message in an alert box, you can use the storeAlert command that will
f etch the message of the alert pop up and store it in a variable.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Q82. How to get the entered text f rom a textbox in the Selenium
webdriver?
Ans. To get the entered text from a textbox in Selenium webdriver, we will use the
getAttribute() method. We will get the value attribute of an element in the HTML
document. The value will be then passed as a parameter to the method.
Ans. T o obtain server-side log in Selenium Server, you can use the command:
IConf igurationListener
IExecutionListener
IHookable
IInvokedMethodListener
IInvokedMethodListener2
IMethodInterceptor
ISuiteListener
IT estListener
IConf igurable
IReporter
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
webdriver?
Ans. For database testing in Selenium webdriver, you require JDBC (Java Database
Connectivity) API. JDBC allows you to execute the SQL statement in the database.
Days
Hours
Minutes
Seconds
Microseconds
Nanoseconds
Milliseconds
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. By using the given command, you can store various windows into one object:
Set<String> multiplewindows=driver.getwindowhandles();
Ans. T o switch one f rame to another f rame, you can use the f ollowing command:
Ans. Bef oreclass is an annotation in T estNG that executes bef ore all the testcases
preceded by @T est annotation.
Syntax:
@Bef oreClass
public void methodname()
{
System.out.println(“NaukriLearning”);
}
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. Af terClass annotation executes af ter every test case when all the tests have
completed execution.
@Af terClass
@Ignore
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
public class T estClass
{
@T est(priority=0)
public void testmeth1()
{
System.out.println(“NaukriLearning”)
}
}
Ans. T o Pass a parameter f rom the XML f ile, you can use:
<test name=”Learning”>
<classes>
<parameter name=”browser”value=”f f ”></parameter>
<class name=”packagename.classname”></class>
</classes>
</test>
</suite>
Ans. T o f etch data f rom the dataprovider method, you can use:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
@T est(dataProvider = “dp1”)
Ans. T o manage data under the dataprovider method, you can use:
@DataProvider
Ans. You can classif y tooltip in selenium webdriver with the title tag and action class.
Write an xpath f or an actual element, get the attribute of the title of that web elements
Syntax:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Ans. By indicating @RunWith(Cucumber.class) and @cucumberOptions annotations
code:
@Runwith(Cucumber.class)
@cucumberOptions(
f eature=”Shiksha Online”,
,glue={“Naukri”,”Learning”},
tags={“@smokesuite”,”@Regrssion”}
)
You can also do something with T estNG groups attributes of @T est annotation.
Example:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
T estNG.xml:
Ans. You can handle the dynamic table using Relative xpath in Selenium.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Data-Driven T esting Framework
Ans. Below is the code snippet to launch the Firef ox browser in WebDriver:
WebDriver driver;
driver.get(“http:// naukri.com/learning”);
driver.quit();
Q103. What is the dif f erence between Silk Test and Selenium?
Ans. T he dif f erences between the Silk test and Selenium are:
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Selenium T est T ool Silk T est T ool
Supports many browsers like Firef ox, Interner Explorer, Supports only Firef ox and
Saf ari, and Opera. Internet Explorer.
Q104. How can you check the visibility of web elements (if an
element is displayed on the screen)?
Ans. T he visibility of web elements can be checked through the f ollowing types WebDriver
commands.
isDisplayed()
Syntax:
isDisplayed():
isSelected()
Syntax:
isSelected():
isEnabled()
Syntax:
isEnabled():
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Q105. How to type text in a textbox using Selenium?
Ans. In Selenium, SendKeys(“String to be entered”) is used to enter the string in the textbox.
Syntax:
// entering username
username.sendKeys(“sth”);
Conclusion
These are the most commonly asked Selenium interview questions and answers. We
hope these interview questions on Selenium will help you land your dream job.
FAQs
What is the dif f erence between implicit wait and explicit wait in selenium WebDriver?
What is the dif f erence between type keys and type commands in Selenium?
What is the dif f erence between verif y and assert commands in Selenium?
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.
Disclaim e r: This PDF is auto -generated based o n the info rmatio n available o n Shiksha as
o n 0 1-No v-20 23.