90+ Selenium Interview Questions for Freshers, Intermediates, & Experienced Professionals
Major companies like Microsoft, HP, and Facebook rely extensively on Selenium for testing purposes. Business Wire reported that with the rise in popularity of Selenium, there was a whopping 300% growth in Selenium job opportunities in the last three years.
If you look forward to working in web development, artificial intelligence, machine learning,or related fields, consider becoming a Selenium expert. This blog explores top Selenium interview questions and answers for freshers, intermediates, and experienced professionals.
Selenium Interview Questions for Freshers
As recent graduates preparing for interviews, you can check out these common questions about Selenium. Practicing these will provide you with confidence and bring clarity to concepts.
1. What is Selenium?
Selenium is an open-source tool used for automating tests done on web browsers. To check the functionality of a web application, a tester writes automated tests using various programming languages in Selenium. To study the Selenium tool in further detail, you can take an online software testing course.
2. Name the different suit components of Selenium.
The four components of Selenium Suite are as follows:
- Selenium IDE: This Integrated Development Environment is a Firefox plugin. It was created for faster development of automation scripts.
- Selenium RC: With this, users can write application tests in various programming languages. For automation, it relies on JavaScript and does not support recording or playback features.
- Selenium WebDriver: It directly communicates with the browser by accepting and sending commands.
- Selenium Grid: It helps in running parallel tests on different machines against different browsers and operating systems.
3. What do you mean by Selenese?
The language used to write Selenium commands is called Selenese. It adds verification or checkpoints in automation tests There are three categories of Selenium commands, Actions (manipulate the state of the application), Accessors (examine the state of the application), and Assertions (verify the state of the application).
4. Why should Selenium be used?
You should use Selenium because of these benefits:
- Offers fast and accurate web application testing.
- Tests web applications on various browsers and operating systems.
- Supports various programming languages.
- Allows simultaneous testing.
5. What are the limitations of using Selenium?
The following are the limitations of Selenium.
- It is an open-source software; therefore, the user does not get much tech support.
- It can test only web applications.
6. What is automation testing?
Automation testing is a software testing technique that checks whether the software is functional or not and running as per the requirements. This is done using automated processes or tests.
7. What are the different testing types supported by Selenium?
The different testing types supported by Selenium are:
- Acceptance testing
- Functional testing
- Performance testing
- Load testing
- Stress testing
- Regression testing
- Test-driven Development
- Behavior-Driven Development
8. Name browsers, programming languages, and operating systems compatible or supported by Selenium.
- Browsers: Google Chrome, Mozilla Firefox, Internet Explorer, Microsoft Edge, Opera, etc.
- Programming Languages: Java, Python, C, PHP, Ruby, Pearl, etc.
- Operating Systems: Android, iOS, Windows, Linux, Mac, etc.
9. Explain the latest version of Selenium.
The latest version of Selenium is Selenium 4.15.0 for Java, JavaScript, .NET, the Grid, and Ruby. For Python, the latest version is called Selenium 4.15.2. The latest version supports Chrome DevTools and you can now download remote files. The Selenium manager in this version is upgraded to support Firefox ESR, Driver, Browser Mirrors, and webview2.
10. Name automation testing tools other than Selenium.
Puppeteer, Cypress, WbDriverIO, Playwright, Cucumber, and NightwatchJS are some of the alternatives to Selenium.
11. Can we test web services or APIs using Selenium WebDriver?
No, we cannot test web services or APIs with Selenium WebDriver as it only tests web applications.
12. How to move to the nth-child element using XPath?
We can move to the nth-child element using XPath with the following expression:
WebElement nthChildElement = driver.findElement(By.xpath(“(//parentElement/*)[n]”));
13. What is the difference between getwindowhandle() and getwindowhandles() commands?
The command getwindowhandle() will return the unique identifier of the current browser window. The command getwindowhandles() will return a set of unique identifiers of all the browser windows opened by WebDriver.
14. What is the Selenium Maven project?
Selenium Maven project is a software project that uses Maven to manage the build process and dependencies of the project. Maven is a build automation tool used mostly for Java projects.
15. What is WebElement in Selenium?
It represents the web elements or the HTML elements on the web page. With WebElement, you can identify and interact with elements on the web page, such as clicking, getting the value, entering text, etc., in the automation testing process.
16. What are some common automation testing tools for functional automation?
Some common automation testing tools for functional automation are Test Complete, Silk Test, RFT, and QTP.
17. What are some common automation testing tools for non-functional automation?
Some common automation testing tools for non-functional automation are Neoload, Apache, JMeter, HP Performance Center, and Silk Performer.
18. What are the basic steps of Selenium testing?
Selenium testing involves the following steps:
- First, launch the web browser.
- Go to a web page you want to test.
- Locate web elements.
- Perform various operations on web elements to check their functionality.
- Verify the results or output.
19. Name some common Selenium commands.
Some common Selenium commands are as follows:
- click() is used to click on a web element.
- getText() is used to retrieve the text from a web element.
- get() is used to launch a web page.
- navigate() is used to go to a particular web page URL.
- refresh() is used to refresh or reload the current web page.
Selenium Interview Questions for 2 to 5 Years Experience (Intermediate Level)
If you have been in the industry for some years now and want to level-up your career by applying for senior job positions, here are some intermediate level interview questions on Selenium for you to practice.
20. How do you locate a web element in Selenium?
The driver.findelement() and driver.findelements() commands are used to locate web elements. ID, Name, LinkTet, CSS Selector, and XPath can be used along with these commands to find the elements.
21. What is an assertion in Selenium? Differentiate between assert and verify commands.
The checkpoints or validations in Selenium are known as assertions. These verify that the application is working as it should. The assert command will check if its conditions are met. If it does not happen, the test will be aborted completely. However, in the verify command, the test keeps running even if certain conditions are not met. In the end, it will report the errors.
22. What is XPath?
XPath is a technique used in Selenium through which a user can navigate to a page’s XML structure. It is used to navigate through elements in an XML document. HTML and XML-based technologies use it to access XML documents.
23. How do you type text in an input box in Selenium?
The command sendKeys() is used to type text in an input box.
24. How to assert the title of a webpage in Selenium?
First, we need to get the title of the webpage and store it in a variable. Then, type the expected title and verify if both are equal. Refer to the following code for a better understanding.
String actualTitle = driver.getTitle();
String expectedTitle = "xyz";
if (actualTitle.equalsIgnoreCase(expectedTitle)) {
System.out.println("Title is Matching");
} else {
System.out.println("Title did not match");
}
25. Explain in brief the wait commands in Selenium.
Various elements load on their own time during testing. Selenium Wait command directs the script to pause for a certain time due to this. There are three types of wait commands, Implicit, Explicit, and Fluent.
26. What is a Page Object Model in Selenium?
Object repositories for web elements are created with the help of a design pattern called Page Object Model. It improves code reusability and readability.
27. What are annotations? Name different types of annotations used in Selenium.
These are a batch of code inserted into the program to control the flow of the method in the script to be used for testing. Different types of annotations in Selenium are Test, BeforeMethod, AfterMethod, and BeforeClass.
28. Differentiate between type keys and type commands in Selenium.
Type keys are characters typed on the keyboard whereas type commands are instructions given to the computer.
29. What is the same origin policy in Selenium?
This policy is a security mechanism that restricts how a script loaded from one origin can interact with a document of another origin.
30. What are the various components of Selenium WebDriver Architecture?
Selenium WebDriver architecture comprises Selenium Client Libraries, Selenium API, JSON Wire Protocol, Browser Drivers, and Browsers.
31. What is Selenium WebDriver? Is it a library?
Selenium WebDriver is a component of Selenium Suite that allows you to conduct automated cross-browser tests. No, it is not a library.
32. What is regression testing in Selenium?
Regression testing is a test type in Selenium used to inspect the behavior of an application after the introduction of a new function or implementation of a bug fix.
33. How to scroll down a page in Selenium using JavaScript?
You can scroll down a webpage in Selenium using JavaScript with the scrollBy() method. Here is an example of the same:
// Use JavaScript to scroll down the page
JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
// Scroll down by a specific number of pixels (e.g., 500)
jsExecutor.executeScript(“window.scrollBy(0, 500);”);
34. What is a data-driven framework and keyword-driven framework?
In a data-driven framework, the test data is separated from test scripts. It allows the same test script to be executed with different sets of data.
In the keyword-driven framework, the test cases are in tabular form, where each row represents a test step, and each of these steps is associated with a keyword. These keywords represent actions to be performed during test execution.
35. How can you enter text in a textbox without using sendKeys()?
You can enter text in a textbox without using sendKeys() with the following command:
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript(“document.getElementById(‘email’).value=“abc@xyz.com”);
36. How will you select a value from a dropdown menu in WebDriver?
‘Select’ class is used in Selenium WebDriver to select a value from a dropdown list. The following is the code for the same:
{
// Open the webpage with the dropdown
driver.get(“https://example.com”);
// Identify the dropdown element (replace with your actual locator)
WebElement dropdown = driver.findElement(By.id(“yourDropdownId”));
// Create a Select object by wrapping the WebElement
Select select = new Select(dropdown);
// Select by visible text
select.selectByVisibleText(“Option 1”);
// Alternatively, you can select by index (0-based)
// select.selectByIndex(0);
// Or select by value attribute
// select.selectByValue(“option1Value”);
// Close the browser
driver.quit();
}
37. Explain the switchTo() command.
The command switchTo() helps in switching between windows, pop-ups, and frames, in a web application. Every window gets a unique alphanumeric value called “Window Handle”.
38. Explain the pause feature in Selenium IDE.
The pause feature is used in Selenium IDE to handle exceptions. You can click on the pause icon on the top right corner of the IDE to use this feature. Here, the script pauses when it finds an exception and enters a debug mode, allowing you to correct the error without failing the entire test case.
39. What are the two types of XPath expressions?
The two types of XPath expressions are absolute and relative. The absolute expressions signify the root element of the document and begin with a forward slash. Relative expressions are relative to the current content. They do not begin with a forward slash.
40. What are XPath attributes?
Attributes in XPath are added to the elements and can contain valuable information about that element. To access an attribute, the at sign (@) followed by the attribute name is used.
41. What is a major disadvantage of implicit wait?
A major disadvantage of implicit wait is that it slows your test. If the element is not identified immediately, the test keeps trying to find it until the duration of implicit wait time, increasing the time of your test suite. Another disadvantage is that if the element takes longer than the implicit wait time, your test can fail.
42. How do you perform drag and drop operations in Selenium WebDriver?
To perform drag and drop operations in Selenium WebDriver, you can use the “Action” class. It is used to perform various actions, such as dragging, dropping, and clicking. To instantiate the “Action” class with WebDriver instance, use the following command:
Actions actions = new Actions(driver);
Next, you can use the drag and drop operations with the dragAndDrop() method.
WebElement draggable = driver.findElement(By.id(“draggable”));
WebElement droppable = driver.findElement(By.id(“droppable”));
actions.dragAndDrop(draggable, droppable).perform();
43. How can you invoke an application in WebDriver?
To launch an application in WebDriver, we can use the “navigate” method or call the “get” method on the driver instance. We can also use third-party tools such as Selenium IDE. However, it requires one to know the URL of the application beforehand.
44. How will you handle alerts in Selenium?
You can handle alerts in Selenium using the Alert interface. To switch to alert, you have to use switchTo().alert() along with accept() or dismiss() methods.
45. How will you set the priority of test cases in TestNG?
You can use the priority parameter to set the priority of test cases in TestNG. The default priority is set to 0. The following method is used to set priority: @Test(priority=1)
46. What is a hub in Selenium Grid?
The hub is a central point or server in Selenium Grid that controls test executions on various devices.
47. What is a node in Selenium Grid?
Nodes are machines attached to the Selenium Grid hub. They have Selenium instances that run the test scripts.
48. What is Page Factory?
Page factory is an implementation of Page Object Model in Selenium. It has the @FindBy annotation for finding web elements.
Selenium Interview Questions for Experienced Candidates
Check out these Selenium interview questions for experienced professionals. If you’re someone with more than 5 years of experience in this industry, this section would be of great help to you.
49. What are the WebDriver-supported Mobile Testing Drivers?
AndroidDriver (can be used on real Android devices or emulators), iPhoneDriver (can only be used on real devices), RemoteWebDriver (tests web applications on mobile devices), and Selendroid (tests Android applications on both real devices and emulators).
50. Mention different types of Navigation commands in Selenium.
These are the four types of navigation commands in Selenium:
- driver.navigate().to(“Give the URL here”); This command will navigate to the specified URL.
- driver.navigate().refresh(); This command refreshes the current page.
- driver.navigate().forward(); This command performs similarly to the operation of the forward button of a browser.
- driver.navigate().backward(); This command performs similarly to the operation of the backward button of a browser.
51. How do you find broken links in Selenium Webdriver?
Using the driver.get() command, one can find if a link is broken or not. If it responds with 200-OK, the link is working. However, in case there is another response, such as 404, 401, etc, the link is broken.
52. What are the different types of pop-ups available in Selenium? How to handle a web-based pop-up?
Alert & confirmation, File upload, Hidden division, File download, Window, and Child browser are different types of pop-ups available in Selenium.
To handle a web-based pop-up, one can use an alert interface with dismiss(), accept(), getText(), and sendKeys() methods.
53. How can you retrieve the CSS properties of an element?
You can use the getCssValue() method to retrieve the CSS properties of any element.
Here is the syntax for the same:
driver.findElement(By.id(“id”)).getCssValue(“name of css attribute”);
54. Which automation tools can be integrated with Selenium to achieve continuous testing?
DevOps, Jenkins, Circle CI, GOCD, Travis CI, and GitLab.
55. Name some widely used Selenium commands.
Some of the widely used Selenium commands are get(), elements(), submit(), linktext(), getCurrentUrl(), and isEnabled().
56. How can you submit a form using Selenium?
You can use the element.submit() method to submit a form in Selenium. The click method can also be used for the same.
57. How to launch different browsers in Selenium WebDriver?
WebDriver driver = new InternetExplorerDriver();
driver.get("http://www.yahoo.com");
By changing the name of the browser, one can launch different ones with the above code.
58. What are TestNG and TestNG listener?
TestNG provides advanced features, such as data-driven testing, annotations, test sequencing, and parallel testing. This helps the user organize their tests more efficiently.
TestNG listeners are annotations that listen to the events in the script and modify TestNG behavior accordingly.
59. How to capture a screenshot in WebDriver?
In Selenium WebDriver, you can take a screenshot using getScreenshotAs() method.
60. What are the parameters you have to pass in Selenium?
The four parameters that you have to pass in Selenium are Host, Port Number, Browser, and URL.
61. What is the framework in Selenium?
The framework is a constructive mix of guidelines, coding standards, processes, mechanisms, etc. to support automation testing.
62. Explain the Object Repository.
All the web elements can be stored in a centralized location by the testers. This location is called the Object Repository.
63. How can you hover over a web element in Selenium WebDriver?
WebDriver driver = new YourDriver(); // Replace YourDriver() with the actual initialization of your WebDriver
// Create an instance of the Actions class
Actions actions = new Actions(driver);
// Identify the web element you want to hover over
WebElement elementToHover = driver.findElement(By.id(“id of the searchbar”));
// Use moveToElement to hover over the identified element
actions.moveToElement(elementToHover).perform();
64. How is Selenium better than QTP (Quick Test Professional)?
Selenium is an open-source software whereas QTP is commercial software. Selenium supports a number of browsers on various operating systems but QTP supports only Internet Explorer on Windows. Selenium supports programming languages like Python, Ruby, etc., whereas QTP only supports VB script.
65. What is the difference between “type” and “typeAndWait” command?
We use the “type” command to enter text into a field on a web page. The “typeAndWait” command is used for a similar purpose but it waits for the page to load before it can jump to the next command. It is helpful in cases where you’re unsure if the text you entered will cause the page to refresh.
66. How to upload a file in Selenium WebDriver?
You can upload a file in Selenium WebDriver with the help of sendKeys() method.
{
// Open the webpage with the file upload functionality
driver.get(“https://example.com”);
// Identify the file input element (replace with your actual locator)
WebElement fileInput = driver.findElement(By.id(“yourFileInputId”));
// Specify the path to the file you want to upload
String filePath = “path/to/your/file.txt”;
// Use sendKeys to set the file path in the file input element
fileInput.sendKeys(filePath);
// Submit the form or perform other actions as needed
// Close the browser
driver.quit();
}
67. How will you set the size of the browser window in Selenium?
There are three functions that are used to change the size of the window. You can either resize, set, or maximize the window.
To resize the browser window:
((JavascriptExecutor)driver).executeScript(“window.resizeTo(1003, 670)”);
To set the window size:
Dimension d = new Dimension(300,500);
driver.manage().window().setSize(d);
To maximize the window size:
driver.manage().window().maximize();
68. How can we handle authentication pop-up in Selenium?
To handle the authentication pop-up, first verify its appearance and handle them using an explicit wait command.
Step1: Use the explicit wait command.
WebDriverWait wait = new WebDriverWait(driver, 10);
Step2: Alert class is used to verify the alert.
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
Step3: Once verified, provide the credentials.
alert.authenticateUsing(new UserAndPassword(<username>, <password>));
69. What is HtmlUnitDriver?
HtmlUnitDriver is a light and fast driver used in Selenium WebDriver for HtmlUnit, which is a headless or GUI-less browser. Since it is GUI-less, it is not seen on screen during test execution.
70. How can you redirect browsing from a browser?
There are three ways to redirect browsing:
- Virtual Private Network (VPN): Use a VPN to encrypt your traffic and route it through a proxy server.
- Web Proxy: It provides access to websites otherwise blocked by your network administrator.
- Browser Extensions: They are helpful to bypass proxy servers configured in your network settings and redirect traffic.
71. What are different types of listeners in TestNG?
There are three types of listeners in TestNG:
- Suite Listeners: It listens to suite execution and allows one to perform actions before or after the suite is executed.
- Method Listeners: It listens to the execution of individual test methods and allows one to perform actions before and after a test method is executed.
- What are different types of listeners in TestNG?
- There are three types of listeners in TestNG:
- Suite Listeners: It listens to suite execution and allows one to perform actions before or after the suite is executed.
- Method Listeners: It listens to the execution of individual test methods and allows one to perform actions before and after a test method is executed.
- Test Listeners: It listens to the test execution and allows one to perform action before and after a test case is executed.
72. How to handle hidden elements in Selenium?
You can use JavaScriptexecutor to handle hidden elements in Selenium. Use the following command to do the same:
(JavascriptExecutor(driver)).executeScript(“document.getElementsByClassName(locator).click();”);
73. How can you find all the links on a web page?
All the links have the anchor tag ‘a’. To locate all the links on the web page, we have to use the tagName ‘a’ in the following command:
List<WebElement> links = driver.findElements(By.tagName(“a”));
Selenium Tricky Interview Questions
Selenium concepts are simple to grasp but some of them need a thorough understanding. Practice these tricky Selenium automation interview questions before your interview to stand out from the rest.
74. Does Selenium support mobile application testing?
It does not directly support mobile application testing. A user has to take the help of a third-party tool, such as Appium to run tests on such applications.
75. Differentiate between driver.close() and driver.quit() command in Selenium.
The command driver.close() is used to close the current browser window, whereas the command driver.quit() is used to close all the open windows in the browser.
76. Can Captcha be automated using Selenium?
No, Captcha cannot be automated in Selenium.
77. What is an exception test in Selenium?
It is a test to verify if an expected exception will be thrown by a piece of code. You can use the test annotation and specify the exceptions in parameters to test the behavior of the code when it encounters exceptions.
78. How can you click on a hyperlink in Selenium?
The command driver.findElement(By.linkText(“New Courses”)).click(); finds the element using link text and clicks on it. Then, the user is redirected to the page.
One can find the element using the substring of the link as well with the command partialLinkText()
79. Can you use screen coordinates while using the click command?
To include coordinates in the click command, you can use the clickAt() command. It accepts the element locator and x, y coordinates as arguments.
Here is the syntax for the same:
clickAt(locator, cordString)
80. What are the two methods to open a URL in Selenium WebDriver?
You can either use the driver.get() method or driver.navigate().to() method to open an URL in Selenium WebDriver.
81. Differentiate between “/” and “//” in XPath.
A single slash or “/” is used to create an XPath with an absolute path from the starting node. On the other hand, the double slash or “//” is used to create an XPath with a relative path. This can begin from anywhere in the document.
82. How do you refresh a web page in WebDriver without losing any changes you made?
There are three ways to refresh a web page without losing the changes made:
- Use the “Reload” button in the browser toolbar.
- Use the keyboard shortcut Shift+F5.
- Right-click on the page and select “Reload” from the context menu.
83. What is a robot framework and how can we use it with Selenium?
Robot framework is an open-source automation framework used for test automation and robotic process automation. We can connect Selenium with a robot framework using the Selenium2Library. It is a robot framework test library that allows you to control web browsers using Selenium WebDriver.
84. What are Jenkins and how are they beneficial when used with Selenium?
Jenkins are servers that automate the software development process. When used with Selenium, they help with the parallel execution of Selenium tests on multiple devices to save time. They also automatically trigger Selenium tests when code changes are made to the repository.
85. How will you handle dynamic elements in Selenium?
We can use the explicit wait method, XPath, or CSS selectors to locate and operate on dynamic elements in Selenium.
86. Why do stale element exceptions occur?
Stale element exceptions occur when the element you interacted with is modified or no longer attached with the DOM. You can handle such exceptions with four different methods.
- WebDriverWait.refreshed()
- Explicit waits
- Try-catch block
- Page Object Model (POM)
87. How will you clear the text in a text field in Selenium?
You can clear the text in a text field in Selenium using the element.clear() method. You can use it to delete default values in the text field.
88. How can you move to a particular frame in Selenium?
You can use the driver.switchTo() command to switch to a particular frame in Selenium. To locate the frame, use either the index, id, or name with the command.
89. How can you check a checkbox in Selenium?
The click() method is used to check a checkbox in Selenium. It is also used to click on radio buttons.
90. What are desired capabilities in Selenium WebDriver?
Desired capabilities in Selenium WebDriver are the set of key-value pairs used to store or configure browser-specific properties.
91. How can you verify tooltip text in Selenium?
The tooltip web elements have an attribute of type ‘title’. We can verify the tooltip text by fetching the value of the ‘title’ attribute. The following is the command for the same:
String toolTipText = element.getAttribute(“title”);
92. How can you fetch the page source in Selenium?
To fetch the page source in Selenium, you can use the driver.getPageSource() command. It returns a string with the page source.
Conclusion
Automation of test scripts has become a demand in the web development industry, with more and more companies looking for Selenium experts. Check out the above-listed Selenium interview questions and answers to upgrade your interview preparation and grab your dream job opportunity. Did you find this blog helpful? Drop us a comment below. Also, check out interview etiquette to impress your interviewer at your next job interview.