0% found this document useful (0 votes)
26 views36 pages

Top 100+ Selenium Interview Questions and Answers: Updated On Jun 7, 2023 15:02 IST

Uploaded by

gopivudataneni92
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)
26 views36 pages

Top 100+ Selenium Interview Questions and Answers: Updated On Jun 7, 2023 15:02 IST

Uploaded by

gopivudataneni92
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/ 36

Top 100+ Selenium Interview Questions and Answers

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.

Q1. How many languages does Selenium support?

Ans. Selenium support various programming languages such as C#, Java, PHP, Ruby,
Python, Perl, Javascript, etc.

Explore popular courses on Shiksha Online:

Popular QA and T esting Courses T op Sof tware T esting Courses

Popular Automation T esting Courses T op Sof tware T ools Courses

Q2. What is automation testing?

Ans. Automation testing or T est Automation is a process of automating the manual process
to test the application/system under test.

Aut omat ed Test ing Process:

Follow the given steps f or automation testing:

T est T ool Selection

Def ine Scope of Automation

Planning, Design and Development

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?

Ans. Following 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

Q4. What are the testing types supported by Selenium?

Ans. Following are the testing types supported by Selenium:

Functional T esting

Regression T esting

Sanity T esting

Smoke T esting

Responsive T esting

Cross Browser T esting

UI testing (black box)

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.

Q6. Which is better – implicit wait or explicit wait?

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.

Q7. When should I use Selenium IDE?

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.

Q9. What is the use of XPath?

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 current node

T agname: T agname of the given node

@ : T o select attribute

Attribute: Attribute name of the node

Value: Value of the 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.

Check out the top Selenium Courses

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.

Q13. Explain what is Data-driven f ramework and Keyword driven?

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.

Keyword-driven f rameworks require the development of data tables and keywords,


independent of the test automation.

Q14. What is Object Repository?

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.

Q15. Mention 5 dif f erent exceptions you had in Selenium


WebDriver?

Ans. T he 5 dif f erent exceptions in Selenium WebDriver are WebDriver Exception,


NoAlertPresentException, NoSuchWindowException, NoSuchElementException,
T imeoutException

Q16. Which web driver implementation is the f astest?

Ans. HT MLUnit Driver implementation is the f astest

Q17. How to f ind more than one web element in the list?

Ans. It can be done using WebElement List. E.g.

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”));

int listSize = elementList.size();


f or (int i=0; i<listSize; i++)
{
serviceProviderLinks.get(i).click();
driver.navigate().back();
}

Q18. What is the dif f erence between driver.close() and driver.quit()


command?

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

Q20. What is Object Repository? How can we create an Object


Repository in Selenium?

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.

Q21. Explain how to navigate to a new window f rom the current


window?

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

Q23. To generate pdf reports, what Java API is required?

Ans. API IT ext

Must Check: API Online Course and Certif icates

Q24. What are the ways you can customize the TestNG report?’

Ans. You can customize T estNG report in two ways:

Using IT estListener Interf ace

Using IReporter Interf ace

Q25. In Selenium, what are Breakpoints and Startpoints?

Ans. A breakpoint is implemented to stop execution to check if the code is working as


expected till now.

A startpoint indicates the point f rom where the execution should begin.

Q26. What are the components of the Selenium suite?

Ans. Selenium suite has f our major components:

Selenium IDE (Integrated Development Environment)

It is an important tool in the Selenium Suite. It is a complete integrated development


environment (IDE) f or Selenium tests. It is implemented as a Firef ox/Chrome plug-in and
speeds up the creation of automation scripts. Selenium IDE allows f or recording, editing, and

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).

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?

Q28. Why should you use Selenium as a test tool?

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.)

Q29. What is Selenese?

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.

T here are three types of commands used in Selenese –

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:

Automation testing Manual testing

Automated testing is f aster and reliable than Manual testing takes a lot of time and
manual testing. human ef f ort.

It is a more accurate method, as it uses It is not that accurate because of human


tools and scripts. errors.

Exploratory testing can be done in manual


It does not allow random testing.
testing.

It is not cost-ef f ective f or low volume It is not cost-ef f ective f or high-volume


regression regression.

Programming knowledge is required in Programming knowledge is not required in


automation testing. manual testing.

Q31. How do we launch a batch f ile in a Selenium Webdriver


project?

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:

Process batch = Runtime.getRuntime.exec(“path of the batch f ile”);

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();

Q32. Elaborate on the f unctioning of Selenium Grid?

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.

Q33. Can we use the Selenium grid f or perf ormance testing?

Ans. Yes, but it is not as ef f ective as Loadrunner, which is a dedicated Perf ormance T esting
tool.

Q34. Is it possible to replace automation testing with manual


testing?

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.

Q35. How will you f ind an element using Selenium?

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.

Q36. What is the Page Object Model (POM)?

Ans. POM is a design pattern responsible f or creating an Object Repository f or web UI


elements.

Q37. What is Page Factory?

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.

Q38. What is an XPath?

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.

Q39. Name dif f erent types of XPath?

Ans. T here are two types of XPath:

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:

//*[@class=’f eatured-box’]//*[text()=’T esting’]

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:

Java -jar “C:\Selenium Webdriver Questions\selenium-server-standalone-2.33.0.jar” -


htmlSuite “*f iref ox” “http://www.google.com” ” “C:\Selenium Webdriver
Questions\SeleniumSuite.HT ML”

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:

Actions act = new Actions(driver);

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.

Check out the Top JavaScript Interview Questions and Answers

Q43. Can Selenium handle windows based pop up?

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.

Must Check: Python Interview Questions and Answer

Q44. How do we handle web-based pop up in Selenium?

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:

// accepting javascript alert


Alert alert = driver.switchT o().alert();
alert.accept();

Q45. Tell me how can I take a screenshot in Selenium WebDriver?

Ans. You can do that by using the T akeScreenshot f unction and by using getScreenshotAs()
method, you can save the screenshot.

Q46. Is it possible to enter a text without using sendKeys()?

Ans. Yes, we can enter/ send a text using JavaScriptExecutor, and we don’t need to use
sendKeys() method.

Q47. What is Junit? What are Junit annotations?

Ans. It is a Java-based unit testing f ramework introduced by Apache. It is an open-source


Framework that of f ers integrations with IDEs such as Eclipse, IntelliJ, etc., allowing you to
execute unit testing easily.

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.

@Ignore: It denotes that this method shall not be executed.

Some of the JUnit Annotations f or specif ic purposes are @ParameterizedT est, @RunWith,
@RepeatedT est, and @Parameters.

Also Read: Top Java Interview Questions and Answers

Q48. What is Object Repository?

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.

Q49. How can we create an Object Repository in Selenium?

Ans. We can create Object Repository in an excel sheet that can be populated inside the
script whenever required.

Q50. Does Selenium have any limitations?

Ans. Yes, it has.

It supports testing of only web-based applications

One cannot test mobile applications

Selenium can’t test Captcha and Barcode readers

It helps to generate reports using third-party tools like T estNG or JUnit

No ready vendor support

User must possess programming language knowledge

Q51. Which browsers/drivers do Selenium WebDriver support?

Ans. Selenium WebDriver supports –

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

Google Chrome – ChromeDriver

HtmlUnit (Headless browser) – HtmlUnitDriver

Internet Explorer – InternetExplorerDriver

IOS – ios-driver/Appium

Saf ari – Saf ariDriver

Q52. Does Selenium Webdriver support web services testing?

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.

Q53. What is an absolute XPath?

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.

Q54. What is a Relative XPath?

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.

Q55. How do we identif y a child element using XPath?

Ans. T o identif y a child element using XPath, we can use the below code:

Syntax: //div/a

Q56. How to use CSS Selector f or identif ying web elements by


class?

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?

Ans. We can use:nth-child(n) to move to the nth child element.

Must Check: CSS Online Course and Certif ication

Must Check: CSS Interview Question and Answer

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.

Q61. What type of tests have you automated?

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.

Q62. Can we launch dif f erent browsers in Selenium WebDriver?

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.

Q63. How to check a checkBox in selenium?

Ans. One can select a checkBox the way a button is clicked.

driver.f indElement(By.id(“idOf T heElement”)).click();

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 .

Q64. Explain the dif f erence between driver.getWindowHandle() and


driver.getWindowHandles() in selenium.

Ans. driver.getWindowHandle() is a unique identif ier and it returns a handle of the current
page

driver.getWindowHandles() returns a set of handles of all the available pages

Q65. What are some possibilities of using conditions in Explicit


waits?

Ans. T he most common possibilities are –

elementT oBeClickable(WebElement element or By locator)

stalenessOf (WebElement element)

visibilityOf (WebElement element)

visibilityOf ElementLocated(By locator)

invisibilityOf ElementLocated(By locator)

attributeContains(WebElement element, String attribute, String value)

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)

textT oBePresentInElementLocated(By, String)

Q66. What are DesiredCapabilities in Selenium WebDriver?

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.

Q67. What is a data-driven f ramework?

Ans. Data-driven is a test automation f ramework. It stores test data in a spread


spreadsheet or table f ormat such as MS Excel Sheets, MS Access T ables, SQL Database,
XML f iles, etc. separated f rom test logic written in test script f iles. Data-Driven T esting
enables engineers to execute tests f or each set of test data values.

Q68. What is a keyword-driven f ramework?

Ans. A keyword-driven f ramework is a type of Functional Automation T esting Framework,


and it works on action word-based testing. T he keyword-driven f ramework helps to
accelerate automated testing by using keywords related to the application being tested.
T hese keywords should be included in every input to describe actions to be perf ormed f or
each step and execute the test successf ully.

Q69. What is a hybrid f ramework?

Ans. As the name suggests, a hybrid f ramework is a combination of one or more


f rameworks and is a combination of data-driven and keyword-driven f rameworks. Here the
test data and test actions are kept in external f iles. T his implements the Page Object Model
T echnique, Data-Driven T echnique, Modular Driven T echnique, Log4j Logging, T estNG
Reporting, and T estNG Reporter Logs.

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.

To learn more about Selenium, read our blog – what is Selenium?

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.

Also Read: Top Software Testing Interview Questions and Answers

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 –

<suite name=”newT estSuite”>


<test name=”newT est”>
<parameter name=”newParamName” value=”newParamValue”/>
<classes>
<class name=”T estFile” />
</classes>
</test>
</suite>

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.

@T est(dependsOnMethods = { “preT ests” })

Q74. What is the dif f erence between “type” and “typeAndWait”


commands in terms of Selenium?

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?

Ans. Dif f erent OS/platf orms supported by Selenium include –

Android

IOS

Linux

Mac OS X

Windows Desktop

Windows Mobile

Q76. What types of cases can be automated using Selenium?

Ans. Selenium can be used to automate the f ollowing types of cases –

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

End-to-end test cases

Functional cases

Integration tests

Regression test cases

Responsiveness cases

Sanity test

Smoke testing

Q77. Mention the list of dif f erent types of locators?

Ans. Dif f erent types of locators are:

By.name()

By.tagName()

By.className()

By.id()

By.linkT ext()

By.xpath

By.cssSelector()

By.partialLinkT ext()

Q78. What is the procedure to iterate through options in the test


script?

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

String[ ] testdata = { “t1” , “t2” , “t3” } ;


// iterate through each test data
For (string s: test data) { selenium.type ( “elementLocator”, testdata) ; }

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

Q80. In Selenium IDE, how to generate random numbers and dates


f or test data?

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()}

Q81. How to retrieve the message in an alert box?

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.

Q83. Mention how to obtain server-side log Selenium Server?

Ans. T o obtain server-side log in Selenium Server, you can use the command:

“java –jar .jar –log selenium.log”

Q84. Mention what are the types of Listeners in TestNG?

Ans. T he types of Listeners in T estNG are:

IConf igurationListener

IExecutionListener

IHookable

IAnnotationT ransf ormer

IAnnotationT ransf ormer2

IInvokedMethodListener

IInvokedMethodListener2

IMethodInterceptor

ISuiteListener

IT estListener

IConf igurable

IReporter

Q85. What API is required f or database testing in the 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.
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.

Q86. Explain when to use AutoIT?

Ans. Selenium is intended to automate web-based applications on various browsers. You


need AutoIT to manage window GUI and non-HT ML popups in the application.

Also Read: Top Manual Testing Interview Questions and Answers

Q87. How to get TagName?

Ans. T o get targeted T agName, you can use below method:

WebElement ele1=driver.FindElement(By.T agName(“T agName val1”);

String tag=ele1.getT agname();


system.out.println(tag);

Q88. Explain the timeout commands in Implicitwait?

Ans. Following are the timeout commands in Implicitwait:

Days

Hours

Minutes

Seconds

Microseconds

Nanoseconds

Milliseconds

Q89. Mention how to store various windows into one object?

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();

Q90. Mention how to switch one f rame to another f rame?

Ans. T o switch one f rame to another f rame, you can use the f ollowing command:

//Click Frames link

driver.f indElement(By.xpath(“xpath val1”)).click();


driver.switchT o().f rame(“packageFrame1”);
driver.f indElement(By.linkT ext(“Alert”)).click();
driver.switchT o().def aultContent(); //Erase all switches bef ore applying switch second
time
driver.switchT o().f rame(“classFrame”);
//Click no f rames link
driver.f indElement(By.xpath(“xpath val1”)).click();

Q91. Explain what is Bef oreclass?

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”);
}

Q92. Explain what @Af terclass is?

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

public void methodname()


{
System.poy.println(“NaukriLearning”);
}

Q93. Explain what @Ignore is?

Ans. Ignore annotation is used to skip method execution.

@Ignore

public void methodname()


{
System.out.println(“NaukriLearning”);
}

Q94. How do you prioritize test methods within a class?

Ans. T o prioritize test methods within a class, 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.
public class T estClass

{
@T est(priority=0)
public void testmeth1()
{
System.out.println(“NaukriLearning”)
}
}

Q95. Mention how to pass a parameter f rom the XML f ile?

Ans. T o Pass a parameter f rom the XML f ile, you can use:

<suite name=”Naukri” >

<test name=”Learning”>
<classes>
<parameter name=”browser”value=”f f ”></parameter>
<class name=”packagename.classname”></class>
</classes>
</test>
</suite>

Q96. How to f etch data f rom dataprovider method?

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”)

public void f (String Naukri, String Learning)


{
//dp1===> dp1 is a method name where we maintain original data
}

Q97. How to manage data under the dataprovider method?

Ans. T o manage data under the dataprovider method, you can use:

@DataProvider

public Object[][] dp1()


{
String data[][]=new String[1][1];
//First Row data
data[0][0]=”NaukriLearning”;
data[0][1]=”123456789″;
}

Q98. How to classif y tooltip in selenium webdriver?

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:

String tooltip = driver.f indElement(By.xpath(“//a[text()=’Projects’]”).getAttribute(“title”);

Q99. Mention how to execute Cucumber Tests in groups using


Cucumber Tags?

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:

Class GroupT estEx1{

@T est(groups = { “Naukri”, “Learning” })


public void testPrintMessage() { }
@T est(groups = { “Naukri” })
public void testSalutationMessage() { }
@T est(groups = { “Learning” })
public void testingExitMessage() { }
}

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:

<suite name = “Suite1”>


<test name = “test1”>
<groups>
<run>
<include name = “Learning” />
</run>
</groups>
<classes>
<class name = “GroupT estExample” />
</classes>
</test>
</suite>

Q100. How to handle dynamic tables in Selenium?

Ans. You can handle the dynamic table using Relative xpath in Selenium.

Q101. Mention what the various types of f ramework are?

Ans. Following are the various types of f rameworks:

Data-Driven T esting Framework

Keyword Driven T esting Framework

Hybrid T esting Framework

Module Based T esting Framework

Library Architecture T esting Framework

Behavior Driven Development Framework

Most Common Frameworks are:

Hybrid T esting Framework

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

Keyword Driven T esting Framework

Q102. Write a code snippet to launch the Firef ox browser in


WebDriver.

Ans. Below is the code snippet to launch the Firef ox browser in WebDriver:

public class Firef oxBrowserLaunchDemo {

public static void main(String[] args) {

//Creating a driver object ref erencing WebDriver interf ace

WebDriver driver;

//Setting webdriver.gecko.driver property

System.setProperty(“webdriver.gecko.driver”, pathT oGeckoDriver + “\\geckodriver.exe”);

//Instantiating driver object and launching browser

driver = newFiref oxDriver();

//Using get() method to open a webpage

driver.get(“http:// naukri.com/learning”);

//Closing the browser

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

Silk test is not a f ree testing


It is a completely f ree testing tool.
tool.

Supports many browsers like Firef ox, Interner Explorer, Supports only Firef ox and
Saf ari, and Opera. Internet Explorer.

Has the f lexibility to use many languages like Java,


Uses text scripting language.
Perl, and Ruby.

Can be used f or client-server


Cab be used f or only web applications.
applications.

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():

boolean buttonPresence = driver.f indElement(By.id(“gbqf ba”)).isDisplayed();

isSelected()

Syntax:

isSelected():

boolean buttonSelected = driver.f indElement(By.id(“gbqf ba”)).isSelected();

isEnabled()

Syntax:

isEnabled():

boolean searchIconEnabled = driver.f indElement(By.id(“gbqf b”)).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:

WebElement username = drv.f indElement(By.id(“Email”));

// 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.

Recently completed any professional course/certification from the market? Tell us


what liked or disliked in the course for more curated content.

Click here to submit its review with Shiksha Online.

FAQs

What is the dif f erence between implicit wait and explicit wait in selenium WebDriver?

Which is better in Selenium, implicit wait or explicit wait?

When should I use Selenium IDE?

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.

You might also like