100 Selenium Interview Questions and Answers
100 Selenium Interview Questions and Answers
100 Selenium Interview Questions and Answers
Want to land your dream job as a Selenium automation tester? Look no further! In this
comprehensive guide, we’ve compiled over 200 of the most relevant and recently updated
Selenium interview questions and answers.
It has seen several upgrades since then, WebDriver 2.0 in 2011, and 3.0 in 2016. Check the
below Selenium timeline.
We can use Selenium to write automation scripts for testing web applications. It helps in
reducing manual testing efforts and improves productivity and quality.
Cross-platform means a Selenium script written on one OS say Windows can run on other
supported systems such as Linux or Mac OS without making any changes.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 1/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Portable means the same script created for a desktop-based device can run on different
supported devices such as tablets, mobiles, etc.
It exposed a set of client APIs which used to send commands to a server to perform actions
on the browser.
Selenium 2.0 a.k.a. WebDriver is a set of native APIs that directly send commands to the
browser instead of delegating to a server.
Its release came out in 2011. It provided the native WebDriver API interface replacing the
old client-server API model.
It is superior to 2.0 because it implemented the W3C specifications for Webdriver APIs to
make them a global standard.
Until 3.0, it was the Selenium community that was supplying Web drivers for specific
browsers. But now, they provide their respective drivers that support the standard Web
driver API interface.
Below block diagram below explains the latest architecture Selenium Webdriver supports.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 2/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Selenium IDE:
A Firefox extension to record and play the user actions performed on a web page.
Selenium RC:
A Selenium Remote Control exposes APIs for scripting tests in different languages and also
runs them in browsers.
Selenium Webdriver:
These are native APIs that directly interact with the browser. They give more control and
are faster than the RC APIs.
Selenium Grid:
It provides concurrency. With its help, we can split testing and run a set of cases on one
machine and some on another.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 3/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Selenium RC is slow because it has an additional JavaScript layer known as the core. On
the contrary, WebDriver is fast as it natively interacts with the browser by utilizing its built-
in engine.
Selenium core can’t ignore the disabled elements, whereas WebDriver handles the page
elements more realistically.
Selenium RC has a mature set of APIs but suffers from redundancies and complicated
commands. On the other hand, WebDriver APIs have a cleaner interface and do not have
any such problems.
Selenium RC doesn’t provide support for the HtmlUnit browser, whereas the WebDriver
has a headless HtmlUnit driver.
Selenium RC includes a test result generator to produce HTML reports. Web Driver
doesn’t have any built-in reporting ability.
Open source: Since it is an OSS, we don’t have to bear any licensing costs for using it.
Cross-browser: It works on all standard browsers such as Chrome, FF, IE, and Safari. We
can run same the test script in all browsers.
Cross-platform: It provides test compatibility across Windows, Linux, and Mac OSX. We
can run same the test script on all platforms.
CLI support: We can create a test suite with hundreds of tests and launch it with a
single command.
CI support: Jenkins is the best CI tool. It provides a Selenium plugin to configure tests
for nightly execution.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 4/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Free help: We can get quick technical support from its large community.
Tester friendly: A non-programmer can also automate using Selenium. It is not too
complicated to be used only by a programmer.
Ongoing project: Active development and bug fixes on the latest project.
Selenium is a perfect clinical tool to impersonate user actions in a browser. However, it also
has a few limitations given below.
Python
Java
C-Sharp
JavaScript
Ruby
PHP
Perl
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 5/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Windows Desktop
Windows Mobile
Linux
Mac OS X
IOS
Android
Functional cases
Acceptance tests
Smoke testing
Cross-browser tests
Integration tests
Responsiveness cases
Q-13. Can you use Selenium for testing Rest API or Web services?
Selenium provides Native APIs for interacting with the browser using actions and events.
The Rest API and the web services don’t have any UI and hence can’t be automated using
Selenium.
Q-14. What are the different types of Web Driver APIs supported in Selenium?
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 6/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
It is none other than the HTMLUnitDriver, which is faster than all of its counterparts.
The technical reason is that the HTMLUnitDriver doesn’t execute in the browser. It
employs a simple HTTP request-response mechanism for test case execution.
This method is far quicker than starting a browser to carry out test execution.
Q-16. How can you use Selenium RC API along with Selenium 2.0/3.0?
We can still invoke Selenium 1.0 API (RC) from the Selenium 2.0 code. But there might be a
few Selenium 1.0 methods missing.
However, we first need to create a Selenium instance from WebDriver and call Selenium
functions.
The old methods might slow down the execution due to the API transitioning happening in
the background.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 7/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Shinya Kasatani was the developer who created the Selenium IDE. The idea crossed his
mind while he was investigating the JavaScript code inside the Selenium core. He then did
a proof of concept and developed it into a full-fledged IDE.
For example, it can detect broken links on a page, check the presence of a web element,
Ajax, JavaScript alerts, and a lot more. There are three main types of command in Selenese.
Actions: It can alter the state of an application. For example, you are clicking on a link,
selecting a value from the drop-down, etc.
Accessors: These commands monitor the state of an application and cache it into some
variable. For example, storeTextPresent, storeElementPresent, etc.
Selenium Grid is a tool that can distribute tests across multiple browsers or different
machines. It enables parallel execution of the test cases. Using this, we can configure to run
thousands of test cases concurrently on separate devices or browsers.
Selenium Grid allows the test cases to run on multiple platforms and browsers
simultaneously, and hence, supports distributed testing.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 8/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
This ability to parallelize the testing is what makes us use the Selenium Grid.
Support concurrent test execution and hence saves us a lot of our time.
After creating multi-machine nodes, we can use them to distribute tests and execute
them.
A hub is analogous to a server that drives the parallel test execution on different machines.
The machine we register to a hub represents a node. The registration allows the grid to
fetch node configuration and execute tests. There could be multiple nodes that we can
bind to a Selenium Grid.
Please make sure to download the Selenium-server jar before running the below command.
Copy
Java: Yes, we can. Moreover, we can do parallel testing using TestNG to utilize the
Selenium grid features.
C-Sharp: Yes, we can. We need to use “Gallio” to run our tests concurrently in the grid.
Ruby: Yes, we can. We’ll use the “DeepTest” to distribute our tests across the grid.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 9/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Q-26. What are Selenium Grid Extras? What additional features does it add to
Selenium Grid?
Selenium Grid Extras is a set of management scripts to manage nodes more efficiently.
Retrieve physical memory (RAM) and persistent storage (Disk) usage statistics
Q-27. What is the difference between the MaxSessions vs. MaxInstances properties of
the Selenium Grid?
1. MaxInstances: It is the number of browser instances (of the same versions) that can run
on the remote machine. Check the below commands.
Copy
-browser browserName=firefox,version=59,maxInstances=3,platform=WINDOWS
-browser
browserName=InternetExplorer,version=11,maxInstances=3,platform=WINDOWS
It means we can run three instances of both Firefox and IE at the same time. So, a total of
six different browsers (FF & IE) could run in parallel.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 10/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
2. MaxSession: It dictates how many browsers (independent of the type & version) can run
concurrently on the remote machine. It supersedes the “MaxInstances” setting.
In the previous example: If the value of "maxSession" is one, then no more than a single
browser would run. While its value is two, then any of these combinations (2FF, 2IE,
1FF+1IE) can run at a time.
Partial Link Text: Uses partial link text to find web elements
Q-29. Which of the id, name, XPath, or CSS selectors should you use?
If the page has unique names or identifiers available, then we should use them.
If they are not available, then go for a CSS selector as it is faster than the XPath.
When none of the preferred locators is present, then you may try the XPath.
XPath is the most-used locator strategy Selenium uses to find web elements.
It works by navigating through the DOM elements and attributes to locate the target
object. For example – a text box or a button or checkboxes.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 11/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Although it guarantees to give you the element you are looking after. But it is slower
compared to other locators like ID, name, or CSS selectors.
In this case, the XPath engine navigates the DOM right from the first node.
In this case, the XPath engine searches for the matching element anywhere in the DOM.
An absolute XPath will always search from the root node until it reaches the target. Such
an XPath expression includes the single forward slash (/) as the prefix.
Copy
/html/body/div[1]/div[5]/form/table/tbody/tr[3]/td/input
A relative XPath doesn’t have a specific point to start. It can begin navigation from any
node inside the DOM and continues. Such an XPath expression includes the double forward
slash (//), as given below.
Copy
//input[@id='username']
Q-35. How do you locate an element by partially comparing its attributes in XPath?
XPath supports the contains() method. It allows partial matching of the attribute’s value.
It helps when the attributes use dynamic values while having some fixed part.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 12/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
The above expression would match all values of the category attribute having the word
‘tablet’ in them.
We can call the text() method. The below expression will get elements that have text
nodes that equal ‘Python.’
Copy
We can use the double dot (“..”) to point to the parent of any node using the XPath.
For example – The locator //span[@id=”current”]/.. will return the parent of the span
element matching the id value as ‘current’.
Q-38. How do you get to the nth sub-element using the XPath?
We can modify the XPath expression to get to the nth element in the following ways:
Copy
# Example
tr[2]
The above XPath expression will return the second row of a table.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 13/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
# Example
tr[position()=4]
We can use the below syntax to access elements using the class CSS selector.
Copy
.<class>
e.g. .color
We can use the below syntax to access elements using ID as the CSS selector.
Copy
#<ID>
e.g. #name
Q-41. How to specify attribute value while using the CSS selector?
Here is the syntax to provide the attribute value with the CSS selector.
Copy
[attribute=value]
e.g. [type=submit]
Q-42. How to access the nth element using the CSS selector?
Here is the syntax to access the nth attribute using the CSS selector.
Copy
<type>:nth-child(n)
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 14/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
e.g. tr:nth-child(4)
Q-43. What is the primary difference between the XPath and CSS selectors?
With the XPath, we can traverse both forward and backward, whereas the CSS selector
only moves forward.
Display a message on the console that the webpage gets loaded successfully.
Source Code:
Copy
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class SimpleWebDriverScript {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
String URL = "https://www.google.co.in";
driver.get(URL);
driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
System.out.println("Webpage gets loaded successfully!!");
driver.close();
}
}
The SearchContext acts as the super interface for the Web Driver.
It is the external interface that has only two methods: findElement() and
findElements() .
We are instantiating an object of the FirefoxDriver class and storing it in the driver
variable.
Q-48. Why do we create a reference variable of type Webdriver, not the actual browser
type?
It is because we could use the same Webdriver variable to hold the object of any browser,
such as ChromeDriver, IEDriver, SafariDriver, etc.
Copy
This approach is right too but will work only the Firefox.
Copy
We combine the username and password strings using the colon separator and stuff them
between the “ http:// ” and the site URL. See the below example.
Copy
http://userid:passcode@somesite.com
e.g. http://userid:passcode@somesite.com
Like many programming languages, Selenium also provides exception handling. The
standard exceptions in Selenium are as follows.
NoSuchElementException: This occurs if the web element with the specified attributes
is not present on the page.
ElementNotVisibleException: This occurs if the element is not visible but is still there
inside the DOM.
In this case, the @Test annotation can help us specify the exception that could occur.
Copy
@Test(actualException = ElementNotVisibleException.class)
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 17/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Verify: It also operates the same as the assert does. However, if the “verify” fails, then it
won’t abort the test and instead continue with the next step.
Q-53. What difference do you make between Soft vs. Hard Assert in Selenium?
Soft Assert: It aggregates the errors that occurred during the test execution. If such an
assertion fails, the control jumps to the next step.
Hard Assert: It immediately responds with an AssertException and breaks the current
test. After that, the next case in the sequence gets executed.
In Selenium Webdriver, the following three types of wait mechanisms are available.
Implicit Wait: It is a wait timeout that applies to a Webdriver instance. It implies that all
actions of this instance will timeout only after waiting for a duration specified by the
implicit wait.
Copy
Explicit Wait: It is an exclusive timeout method that works by adding code to delay the
execution until a specific condition arises. It is more customizable in terms that we can set
it up to wait for any suitable situation. Usually, we use a few of the pre-built Expected
Conditions to wait for elements to become clickable, visible, invisible, etc.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 18/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
Q-57. What is the command to enter text in the HTML text box using Selenium?
Copy
Q-58. How to enter text in the HTML text box without invoking the sendKeys()?
Copy
Q-59. What is the method to read the JavaScript variable using Selenium WebDriver?
Again, we can utilize the JavascriptExecutor class to read the value of a JS variable. See the
below code.
Copy
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 19/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Q-60. What is the command to reset the HTML text box in Selenium Webdriver?
Selenium provides the clear() function to reset the value inside the text element.
Copy
Q-61. What is the command to get the value of a text box in Selenium Webdriver?
Selenium provides the getText() function to read the value inside the text element.
Copy
package webdriverdemo;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class demoClass {
@Test
public void readText() {
System.setProperty("webdriver.chrome.driver", "
<<chromedriver.exe>>");
WebDriver webdriver = new ChromeDriver();
webdriver.get("https://www.google.com");
String strText = webdriver.findElement(By.xpath("<<xpath
expr>>")).getText();
System.out.println("Text element contains: " + strText);
}
};
Q-62. What is the command to get the attribute value in Selenium Webdriver?
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 20/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Selenium provides the getAttribute(value) function to read the value inside the text
element.
Copy
Copy
webdriver.findElement(By.linkText("Selenium Interview
Questions")).click();
Q-64. What is the command to submit the HTML form in Selenium Webdriver?
Copy
webdriver.findElement(By.id("<<htmlform>>")).submit();
However, we can also achieve the same effect by calling the click() method.
Q-65. What is the command to press enter inside the HTML text box using Selenium
Webdriver?
Copy
webdriver.findElement(By.xpath("<<xpath>>")).sendKeys(Keys.ENTER);
Q-66. What is the Selenium command to delay test execution for 10 seconds?
In Java, we can use the following method to halt the execution for a specified no. of
milliseconds.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 21/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
java.lang.Thread.sleep(long milliseconds)
Copy
Thread.sleep(10000)
Q-67. Is it mandatory to prefix the URL with HTTP or HTTPS while calling the web
driver’s get() method?
Yes, if the URL doesn’t contain the HTTP prefix, then the program will throw an exception.
Hence, it is mandatory to pass the HTTP or HTTPS protocol while calling the web driver’s
get() method.
Q-68. What is the other method that gives the same effect as we get from the web
driver’s get()?
Selenium provides the <navigate.to(link)> method. It does the same thing as we achieve
from the get() call.
Q-69. What is the principal difference between the “GET” and “NAVIGATE” methods?
The get method makes a page load, extracts its source, or parses the full text. On the
contrary, the navigate method tracks the history and can perform operations like refresh,
back, and forward.
For example – We like to move forward, execute some functionality, and then move back
to the home page.
Q-70. How can I move back and forth in a browser using Selenium?
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 22/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Selenium provides the following methods for moving back and forth in a browser.
1) navigate().forward() – to move to the next web page as per the browser’s history
2) navigate().back() – to move back to the previous page as per the browser’s history
3) navigate().refresh() – to reload the current page
4) navigate().to(“URL”) – to start a new browser window and open up the specified link
Q-71. What is the Selenium command to fetch the current page URL?
To retrieve the current page URL, we can call the getCurrentURL() function.
Copy
webdriver.getCurrentUrl();
Copy
webdriver.manage().window().maximize();
Copy
webdriver.manage().deleteAllCookies();
Q-74. State the difference between the Web driver’s getWindowHandle() and
getWindowHandles() methods.
Copy
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 23/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
Q-75. State the difference between the Web driver’s close() and quit() methods.
These two methods perform the same task, i.e., the closing of the browser. However, there
is a slight difference.
Copy
Copy
Q-76. State the difference between the Web driver’s findElement() and findElements()
methods.
Both these methods traverse the DOM looking for the target web element. However, there
are some basic differences between them.
1. The findElement() method returns the first WebElement matching the locator, whereas
the findElements() fetches all passing the locator criteria.
Copy
// Syntax of findElement()-
WebElement item = webdriver.findElement(By.id("<<ID value>>"));
Copy
// Syntax of findElements()-
List <WebElement> items = webdriver.findElements(By.id("<<ID value>>"));
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 24/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
We can use the isElementPresent() command to verify the object on all pages.
Copy
assertTrue(selenium.isElementPresent(locator));
Q-78. How do you check for the presence of a web element after the successful page
load?
We can verify the presence of a web element with the following code.
While using the below function, supply some timeout value (in seconds) to check the
element in a regular interval.
Copy
GetText(): You may call it to find out the text shown by the alert.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 25/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
1. Use the Robot class (Java-based) utility to simulate the keyboard and mouse actions.
That’s how you can handle the window-based popups.
2. The KeyPress and KeyRelease methods simulate the user pressing and releasing a
specific key on the keyboard.
Selenium provides the getWindowHandles() method, which returns the handles for all
open popups.
We can store them into a <String> variable and convert it into an array.
After that, we can traverse the array and navigate to a specific window by using the below
code.
Copy
driver.switchTo().window(ArrayIndex);
Alternatively, we can use the Java Iterator class to iterate through the list of handles. Find
below the code to handle multiple windows using Selenium.
Copy
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 26/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
}
}
Selenium doesn’t have a direct API to access a database. Hence, we can look for its support
in the programming language we choose to work with Selenium.
Java provides the Connection class to initiate a connection with the database. It has a
getConnection() method that we need to call. For this, we’ll make a Connection Object. It’ll
manage the connection to the database.
Please note: An application could have one or more connections opened to a database or
different databases.
The DriverManager class then attempts to find a driver to access the database URL.
After it finds a suitable driver, the call to the getConnection() method succeeds.
Syntax:
Copy
Consider the Google search text box, which is an Ajax control. Whenever we write some
text into the box, it shows up a list of auto-suggested values.
To automate this type of element, we need to grab the above list in a string as soon as the
box receives input. After that, we can split and take the values one by one.
Sometimes, the WebDriver itself manages to work with the Ajax controls and actions.
However, if it doesn’t succeed, then try out the below code.
Copy
First of all, both these terms belong to the Page Object Model (POM), a design pattern in
Selenium. Let’s now see how are they different from each other.
Page Object is a class in POM corresponding to a web page. It captures the functionality as
functions and objects as members.
Copy
public LogInPage() {
}
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 28/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Page Factory is a method to set up the web elements within the page object.
Copy
@FindBy(id="password")
private WebElement pass;
public LogInPage() {
PageFactory.initElements(browser, this); // Setup the members as
browser.findElement()
}
Q-87. What are User Extensions, and how do you create them?
User extensions are a set of functions written in JavaScript. They are present in a separate
known as the extension file. Selenium IDE or Selenium RC access it to activate the
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 29/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
extensions.
Selenium’s core has a JavaScript codebase. So, we can also use it to create the extension.
Copy
// sample
Selenium.prototype.doFunctionName = function(){
The function name begins with a “do” prefix. It signals Selenium to interpret this function
as a command.
It means we can call the above function inside any of our steps.
Sometimes, an image than a trace log can help us identify the right reason for an error. The
code in the below example will capture the image and store it in a file.
Copy
Import org.apache.commons.io.FileUtils;
WebDriver ins = new ChromeDriver();
ins.get("http://www.google.com/");
Q-89. How to simulate Mouse over action on a submenu option under a header menu?
Using the Actions object, you can first move the menu title, and then proceed to the popup
menu item and click it. Don’t at all miss to invoke the <actions.Perform()> at the end. Check
out the below Java code:
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 30/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
Q-90. How to resolve the SSL certificate issue (secured connection error) in Firefox
with WebDriver?
There can be many reasons for the secured connection error. It could be because of the
following:
While a site is being developed, it may not have the right SSL certificate.
The SSL may not have been configured appropriately at the server end.
However, you still want to test the site’s standard functionality using Selenium. Then, the
idea is to switch off the SSL setting and ignore the SSL error.
Copy
ssl.setAcceptUntrustedCertificates(true);
ssl.setAssumeUntrustedCertificateIssuer(false);
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 31/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
In Internet Explorer, it is somewhat trivial to ignore the SSL error. Please add the below line
of code and safely skip the SSL issue.
Copy
driver.navigate().to("javascript:document.getElementById('overridelink').
click()");
Selenium implements a PROXY class to configure the proxy. See the below example:
Copy
Copy
chrome_opt = webdriver.ChromeOptions()
chrome_opt.add_argument('--proxy-server=%s' % PROXY)
chrome = webdriver.Chrome(options=chrome_opt)
chrome.get("<< target URL >>")
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 32/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
TestNG annotations prioritize the calling of a test method over others. Here are the ones
to use with Selenium:
@AfterClass – to run only once after all the test methods of the current class finish
execution.
@BeforeTest – to run before any test method inside the “Test” tag.
@AfterTest – to run after any test method inside the “Test” tag.
In TestNG, the “@Parameters” is a keyword that allows the arguments to pass to “@Test”
methods.
The data provider is a TestNG annotation. It allows you to pass parameters like a property
file or a database to a test method.
It is an innovative TestNG feature that didn’t exist in the JUnit. You can assign methods
with proper context and refine groupings of test methods.
You can not only link methods to groups but also tell groups to include other groups.
TestNG framework allows multiple tests to run by using the test group feature.
We can associate a single test with multiple groups, as shown in the below example.
Copy
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 33/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Copy
<suite name="SuperSuite">
<suite-files>
<suite-file path="subSuite1.xml" />
<suite-file path="subSuite2.xml" />
...
</suite-files>
</suite>
Q-101. What are the Open-source frameworks (OSF) does Selenium support?
JUnit
TestNG
Maven
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 34/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
FitNesse
Xebium
Usually, the test cases receive the data from the external files (XLS or CSV) and store
them into variables. Later during execution, the variables serve as input as well as
verification points.
In KDF, there happens to be a table of keywords. Every keyword either maps to an action
or an object.
The actions reflect the product functionality, and the objects represent its resources
such as web elements, commands, or the DB URL, etc.
They remain detached from the test automation suite. Hence, the creation of the tests
can continue with or without the AUT (application under test).
The keyword-driven tests cover the full functionality of the application under test.
A data-driven framework works on the concept of separating data from the tests. It solely
depends on the test input data.
Q-104. What are the two most common practices for automation testing?
The two most frequently used practices for automation are as follows:
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 35/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
The concept of TDD came to light while a few XP (Extreme Programming) developers
conceived it.
It intends to prepare tests to check if the code breaks or not. After each test case failure,
the developer should fix and re-run the test to verify the same. This process should repeat
until all units function as per the design.
BDD follows most of the principles of TDD but replaces its unit-centric approach with a
domain-centric design.
It intends to bring in inputs not only from the Dev or QA but an array of stakeholders such
as Product Owners, Technical Support, Managers, and Customers.
The goal is to identify and automate appropriate tests that reflect the behavior sought by
the principal stakeholders.
Q-107. What are the main traits of a Software test automation framework?
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 36/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Report creation
Q-108. What type of test framework did you create using Selenium?
While replying to such questions, stay focused, and keep your answer short and crisp. You
can start by talking about the different components in your framework and then explain
them one by one.
I’ve created a page class for every web page in my application. It keeps the objects and
the handler functions.
Every page class has a follow-up test class where I create tests for related use cases.
I used separate packages to host the pages and their test classes. It’s best practice to do
it that way.
The framework also had a lib package for utility and some standard wrapper functions
over Selenium APIs.
Java is a core programming language used for this project. It was primarily because the
team had previous Java experience. Also, we could utilize the TestNG annotations and
report features.
Most test cases are data-driven. They require input from the external data source. So, I
used the Java property/POI class to read from the CSV/XLS files.
We used the TestNG group feature for labeling test cases as P1, P2, and P3.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 37/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
The Log4J library provided the necessary support for tracing in our project.
Instead of using the TestNG reporting, we preferred the Extent report. It has more
graphical options and gives an in-depth analysis of the results.
We built the framework with the help of Maven. Also, Jenkins provided support for
automated build and execution.
Q-109. What challenges have you faced with Selenium? And how did you overcome
them?
Here are some of the problems that testers usually face while doing automation with
Selenium.
Wrong implementation: I used the page object model but had it implemented
incorrectly. My classes were focussing on the web elements rather than they should have
resembled the user actions.
Duplicate code: The project had many category pages. Each category had a different
search function instead of handling them at a central place.
Ineffective use of wait: I used implicit wait with a fixed timeout. However, some pages
were timing out due to higher load time. I had to adopt the Fluent wait (with a variable
timeout) to overcome this problem.
Improper error handling: It was getting hard to debug the cause of a failed test. In
some places, the {try-catch} blocks were missing, and hence, cases were skipped w/o giving
a proper reason. Therefore, I had to refactor the code by adding assertions and exception
handling.
Inconsistent XPath: Most of the locators were using the XPath method. And the
developers kept them changed while fixing new defects. I called up a discussion with them
and agreed to have a fixed XPath or an ID for the web elements.
Performance & Localization: We were using the flat files (CSV) initially to feed data to
test cases. However, it had us fail in testing localization as well as beat us on the
performance. Ee migrated all of our test data to MySQL and fixed both issues.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 38/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Monolithic tests: Earlier tests didn’t use labeling. Honestly, there wasn’t a way to do it.
Hence, we integrated our test suite with TestNG and got away with this limitation. Now, we
have many test groups like features-based (F1, F2, F3…), and priority-based (P1, P2, P3).
Q-110. What benefits does TestNG have over the JUnit framework?
1. In JUnit, we start by declaring the @BeforeClass and @AfterClass. However, there isn’t
such a constraint in TestNG.
5. We can make a case depend on another in TestNG, whereas in JUnit, it’s not possible.
6. TestNG allows the grouping of tests, whereas JUnit doesn’t. Executing a group will run
all tests under it. For example, if we have a number of cases distributed in two groups,
namely the Sanity, and Regression. If the requirement is to run the “Sanity” tests, then we
can configure TestNG to execute the tests under the “Sanity” group. TestNG will execute all
cases associated with the “Sanity” group.
Get ahead of the competition and land your dream job with our extensive list of updated
Selenium interview questions and answers! Our team of experts has carefully reviewed
each question to ensure accuracy, and we’ve even included refactored answers that
provide more value to our readers.
But wait, there’s more! Our website offers a range of additional resources to help you build
your Selenium skillset, including tutorials, articles, and more. Check out the “You Might
Also Like” section beneath this tutorial.
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 39/40
9/8/24, 9:40 PM 100 Selenium Interview Questions to Land a Job
Don’t waste any more time searching for interview questions – we’ve got you covered.
With our comprehensive list, you’ll be well-equipped to ace any Selenium interview and
impress potential employers.
You can receive regular and timely updates on Selenium by following us on our social
media accounts.
Best,
TechBeamers
https://techbeamers.com/latest-selenium-interview-questions-and-answers/ 40/40