Are you attending an important interview and wondering what are all the Selenium interview questions you will go through?
We have created this most-read Selenium interview questions and answers guide to help you understand the depth of the questions and face it with confidence.
Further, since they are manual, they are prone to errors. Manual testing does not help in the long run, and so, automated testing like Selenium is gaining demand in the industry. If you are pursuing your career in automated testing, and have an upcoming interview in Selenium, this blog is meant for you.
In this blog, we shall discuss here the most common Selenium interview questions. These are for both – the beginners as well as Selenium interview questions for experienced.
Check out our free courses to get an edge over the competition.
Selenium Interview Questions & Answers 2022
Q.1) Why pick Selenium over other automated testing tools?
Selenium is open-source. It is very easy to adapt compared to other automated tools in the market. Due to this reason, many companies picked up Selenium automated testing over other traditional methods.
Refer to the key attributes of Selenium to understand its vast adaptability-
|Open Source Platform||It is freeware and portable. There are no direct costs involved with Selenium. It can be downloaded for free and gets community-based support.|
|Language Support||Supports various languages such as Java, Python, Ruby, C# and more. It has its script, but that is not a limitation, as programmers can work with any language.|
|Browser support||There is a support across multiple browsers such as Chrome, Firefox,Internet Explorer, Opera and more. It becomes useful for programmers while testing.|
|Operating Systems Support||It can be operated across multiple operating systems such as Windows, OS, Linux, etc.|
|Device support||Supports tests across devices, as the test can be implemented on Android, iPhone and Blackberry.|
|Reusability and add-ons||The programmers can use scripts that can be tested across multiple browsers. Multiple tests can be executed using Selenium, which covers almost all the aspects of functionality testing by implementing the add-on tools.|
|Programming languages support||It can be integrated with various programming languages and frameworks, such as ANT, Maven, Jenkins, Hudson, and more.|
Q.2) List some benefits of Selenium over tools like TestComplete and QTP. Also, what are the disadvantages?
Selenium does not require a license, unlike TestComplete and QTP, being easy on pockets. The online community offers massive support. The release cycles are smaller, and the feedback is prompt compared to TestComplete and QTP. Further, Selenium works on Mac, Linux, and Windows as well.
On the contrary, Selenium requires a developer to have high coding skills. Whereas QTP and TestComplete require low to moderate level of coding skills, respectively.
Refer to the below-mentioned table to understand the advantages and disadvantages of Selenium-
|Open- source software||No reliable technical support.|
|Supports various programming languages||Only support web- based applications.|
|Supporys multiple operating systems (Android, iOS, etc.)||Takes more time test cases.|
|Supports various browsers (Chrome, Firefox, Safar, Internet Explorer, etc.)||Difficult to setup Test Environments|
|Supports Parallel Test Execution||Limited Image Testing Support|
|Test cases can be implemented while the browser window is minimised.||No built- in reporting facility|
|Faster than other tools.||No test tool integration for executing test management.|
Check out upGrad’s Advanced Certification in Blockchain
Q.3) What changes have occurred in the various Selenium version upgrades?
In the first version of Selenium, Selenium v1, it only comprised three suites of tools, which are Selenium IDE, RC, and Grid. The Webdriver was missing. It was only in the second version of Selenium, Selenium v2 that the Webdriver was introduced. Once this was done, Selenium RC was no longer in use.
You can find them in the market, but the support isn’t available. The next version of Selenium is Selenium v3. It consists of Webdriver, IDE, and the Grid. It is currently in use. A newer version, Selenium v4, is also now available.
Selenium IDE is mainly for recording and playing back. The Webdriver is for testing the dynamic web applications using a programming interface. The Grid is used for employing tests in remote host machines.
You must use the IDE for recording and playback of tests. A WebDriver is used for testing active web applications using a programming interface, and the Grid is employed for deploying tests in isolated host machines.
Refer to the below-mentioned table to understand the difference in various Selenium upgrades-
Check out upGrad: Full Stack Development Bootcamp (JS/MERN)
Explore our Popular Software Engineering Courses
Q.4) What are the various exceptions in Selenium WebDriver?
Just like any other programming language, you can find exceptions in Selenium as well. You can find the following exceptions in Selenium WebDriver:
TimeoutException: You get this exception when a command does not perform an action in the specified time.
NoSuchElementException: You get this exception when it cannot find an element with the given attributes on a web page.
ElementNotVisibleException: You get this exception when an element is available in the document object model, but it is not seen on the web page.
StaleElementException: You get this exception when an element is not attached to the document object model or is deleted.
NoAlertPresentException: It is a type of popup, which provides important for users.
NoSuchWindowException: It is a popup that occurs when the driver in the Selenium Program code is unable to find the pop-up window on the web page in order to switch.
SessionNotFoundException: When the driver is trying to perform operations on the web application after the browser is closed.
InvalidSelectorException: It is a sub class of NoSuchElementException class and occurs when a selector is incorrect or syntactically invalid.
ElementNotSelectableException: It indicates the presence of the web
element but not its selectabiity.
Q.5) Explain Selenium exception test
The exception you expect to be thrown inside a test class is an exception test. If you write a test case intending it to throw an exception, you must use the @test annotation and also mention it in the parameters that which exception would be thrown. For instance,
@Test(expectedException = NoSuchElementException.class)
Q.6) Is there a need for an excel sheet in a project? Is yes, how?
Excel sheets are used as a data source during testing. Further, it also stores the data set while executing data-driven testing. When excel sheets are used as a data source, it can store:
Application URL: Developers can mention the environment URL under which the testing is executed. For example, testing environment, development environment, QA environment, production environment, or staging environment.
User name and password information: Excel sheets can keep safe the access credentials like the username of a password of various environments. Developers can encrypt and store these details for security reasons.
Test cases: Developers can make a table wherein one column write the test case name and the other which says to be executed or not.
If you are going to use excel sheets for DataDriven Test, you can easily store the information for various duplications to be executed during the tests. For instance, all the data that needs to be written in a text box for testing on a web page can be stored in the excel sheets.
It can be defined as the problem that occurs during the test execution. On the occurrence of the exception, the program stops and so does the codes. The codes will not get executed in this scenario.
There exists three types of execution in Selenium-
- Checked Exception- Handled during compile time. They cause compile problem if not handled at the right time.
- Unchecked Exception- A compiler does not mandate to handle.
- Error- Occurs when the scenario becomes fatal and unable to be recover.
upGrad’s Exclusive Software and Tech Webinar for you –
SAAS Business – What is So Different?
Q.7) What is POM? List its advantages?
POM stands for Page Object Model. It is a design pattern for creating an Object Repository for web UI elements. Every single web page in the application must have its own corresponding page class, which is in charge of searching the WebElements in that page and then execute operations on them.
POM in selenium acts as a design pattern that used in test automation creating a object repository for web UI elements. It assists in reducing the code duplication and improving test maintainence.
There should be a corresponding Page Class for each web page in the application. The Page Class faciliates in identifying the Web Elements of that particular web page. It also contains the Page methods that performs operations on the WebElements. This is how to explain how to explain pom in interview.
The advantages of using the Page object model are:
- It makes the code readable by letting developers separate operations and UI flows from verification.
- Several tests can use the same Object Repository because it is independent of Test Cases.
- The code becomes reusable.
This is how you can tackle pom in selenium interview questions. Now while answering, page object model in selenium interview questions you could also choose to mention the elements of POM. Some of the elements are listed below-
- Plugin tests
- Plugin configuration
- Developers and contributors
- Plugin executions with matching IDs
This is also how to explain page object model framework in interview. You can read the room, and add or deduct from your answers.
Q.8) What is a Page Factory?
Page Factory offers an enhanced method to execute the Page Object Model by efficiently using the memory, and the execution is done using object-oriented design.
|With Page Factory||Without Page Factory|
|Uses By()||Uses @FindBy()|
|No imports are required||Imports Page factory|
|No cache storage||Cache lookup is faster|
Page Factory initializes the elements of the Page Object or instantiates the Page Objects itself. Annotations for elements can also be produced. It is, in fact, a better way as the describing properties may not be expressive enough to differentiate one object from another
If POM is used without a page factory, instead of having to use ‘FindElements,’ @FindBy is used to look for WebElement, and initElements is used to initialize web elements from the Page Factory class.
@FindBy can accept attributes like tagName, name, partialLinkText , linkText, id, className , css, and xpath.
The Page Factory is a class provided by the Selenium Web Driver to implement the POM. The Page Object Repository is separated from the test methods with the help of Page Factory Concept.
Some of the other Page Factory annotations-
In page object model interview questions, you can definitely expect a question of Page Factory. You may choose to make a slight mention of the Page Factory while responding to what is pom in selenium. Or during pom selenium interview questions, if the interviewer ask a separate question on Page Factory, you may get into depth of it to answer. As mentioned above. Moreover, during the POM interview questions, the interviewer could also twist their way of asking, instead of descriptive questions, they could also throw some MCQs your way, such as the design pattern called page object model mcq.
Q.9) How do you achieve synchronization in WebDriver? Or, tell us about the different types of wait statements Selenium Web Driver?
Synchronization in WebDriver should be achieved using WebDriver Wait. In case a specific element the programmer is working on takes time, then they should use WebDriver Wait.
You can find two wait statements in Selenium web driver, namely, Implicit Wait and Explicit Wait.
Implicit wait commands the WebDriver to wait for a little by polling the DOM. It is present for the complete life of the web driver instance, once the implicit wait is declared. The pre-set value is zero. If you set it more than zero, then the behavior will poll the DOM on a regular basis based on the driver implementation.
Explicit wait commands the execution to wait for a little till a condition is attained like:
Read: Spring Interview Questions & Answers
These methods are executed in the selected window or frame. This chosen script runs as an anonymous function. The script can return values, the returned data types are-
- Web Element
Explore Our Software Development Free Courses
|Blockchain Technology||React for Beginners||Core Java Basics|
Q.12) How do you handle mouse and keyboard actions using Selenium?
Special mouse and keyboard actions are handled using Advanced User Interactions API. It comprises of the Actions and the Action Classes that are required for performing these events. The most used mouse and keyboard events are given by Action class are:
dragAndDrop(): This event performs click-and-hold at the position of the source element, moves.
source, target(): Moves to the position of the target element and releases the mouse.
clickAndHold(): It clicks the current location of the mouse.
Q.13) What are various types of Selenium frameworks?
The various types of Selenium frameworks are:
- Keyword Driven Framework: In this framework, the operations and instructions are written in a separate file like Excel. It is based on keywords that forms the basis of functionality. It might need repetitive writing to perform some actions in case when the code has to cover a lot of functionality. That is why the operators or methods that are required to be performed are written separately from the script in form of keywords.
- Data-Driven Framework: In this framework, full test data is taken from some external source files like an XML, Excel, CSV, or some other database table. It is based on different datasets that ar ecraeted on externa files such as excel and are imported into the automation testing tool. These datasets are engineered to be kept separate from the original script, thus increasing the accuracy.
- Hybrid Framework: This framework is a blend of both the Keyword Driven framework and the Data-Driven framework. The framework uses different keywords and datasets.
Q.14) Name a few files that serve as a data source for various Selenium frameworks.
They can be an XML, Excel, CSV, or even a Text file.
Q.15) What is Selenese?
Selenese is the group of selenium commands to test a web application. Developers can use Assertions, Actions, and Accessors. Assertions are used as checkpoints. Actions are for running operations, and Accessors are used to store the value of a variable.
These Selenese commands are used to test web-applications. It can easily verify the presence of an element. There are three types of commands that Selenese uses, such as-
- Actions- These commands can change the condition of an application. For example, clicking of a checkbox, form submission, dropdown selection and so on. In case of non-performance, the test fails.
- Accessors- These commands verify the state of application. They also keep a track of application.
- Assertions- These commands are used to check the state of applications against the expected conditions.
Q.16) What is the major difference between a Page Factory and Page Object Model (POM)?
A common selenium interview question. A page factory is a method to initialize web elements within the page object on the creation of the instance. On the other hand, the page object model is a class that states the web page and holds its functionalities.
Q.17) Does Selenium support handling window pop-ups?
No. Selenium does not support handling pop-ups. An alert, which is a pop-up window, displays a warning message on the screen. You can achieve this by using a few methods like:
Void dismiss(): When the cancel button is clicked in the alert box, this method is called.
Void accept(): When the ‘OK’ button of the alert is clicked, this method is called.
String getText(): If you want to capture the alert message, you must call this method.
Void sendKeys(String stringToSed): If you want to send some information to the alert box, you must call this method.
Read: React Interview Questions & Answers
Q.18) Explain Robot class
A Robot class gives control over the keyboard and mouse devices.
The methods comprise:
- KeyPress(): Called on the event where you want to press a key.
- KeyRelease(): Called in the event to release the pressed key.
- MouseMove(): Called in the event when you have to move the mouse pointer in the X and Y coordinates.
- MousePress(): Called in the event when you press the left button of the mouse.
- MouseMove(): Called in the event of releasing the pressed button of the mouse.
The Robot Class is used to activate the automated testing for implementation of Java platform. The robot class is easy to implement and can be integrated with an automated framework.
Benefits of Robot Class-
- It can simulate the Keyboard and Mouse Event.
- Help in upload/ download of files using the Selenium web driver.
- Can easily be integrated with the current automation.
Q.19) How to handle many windows in Selenium?
The window handle is a special identifier that has the address of all the windows. It serves as a pointer to a window returning the value in the string.
- get.windowhandle(): It gets the current window handle.
- get.windowhandles(): Gets the handles of all the windows opened.
- switch to: Helps in switching across the windows.
- set: Sets the window handles, which is in the form of a string.
- action: helps to execute certain actions on the windows.
Q.20) What are Listeners?
The interface that changes the behavior of the system is called listeners in Selenium. They enable customizations of logs and reports. They are of two kinds: TestNG listeners and Webdriver listeners.
They have the ability to listen to any event like data entering, page navigation and so on.These are defined with the help of interface. T modifies the behavior of technology and also indulges in providing reports customisation and logs.
Types of listeners in TestNG are mentioned below-
- Suite Listener
- Annotation Transformer
In-Demand Software Development Skills
Q.21) Explain Assert and Verify commands
Assert: An assertion is used to differentiate between the real result and the expected result.
Verify: The test executions aren’t paused no matter if the verify condition is true or false.
Q.22) How does one navigate back and forth on a webpage?
It is one of the most common selenium interview questions.
You can use the below methods to navigate back and forth.
Q.23) How to send ALT/SHIFT/CONTROL key in Selenium WebDriver?
Typically using the keys like ALT, Shift, or Control, we combine them with other keys to activate a function. We cannot just click them alone. We need to define two methods for the purpose of holding onto these keys while the following keys are
pressed: keyUp(modifier_key) and keyDown(modifier_key)
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Objective: The purpose is it performs a modifier keypress without releasing the modifier key. Following interactions may assume it’s kept pressed.
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONTROL)
Objective: The purpose is it performs a key release.
So, with a mix of these two methods, we can capture the special function of a particular key.
Q.24) How do we take screenshots in Selenium WebDriver?
The TakeScreenshot function helps to take a screenshot in Selenium Webdriver. Further, you can save the screenshot taking by using getScreenshotAs() method.
File scrFile = ((TakeScreenshot)driver).getScreenshotAs(outputType.FILE);
Q. 25) Can we set the size of the browser window using Selenium? If yes, how?
Yes. If you wish to maximize the size of browser window, you need to use the code
If you wish to resize the current window to a specific dimension, you must use the setSize() method. For instance:
Dimension d = new Dimension(420,600);
If you wish to set the window to a particular size, you must use window.resizeTo() method.
Q.26) How to select a value from the dropdown? How to handle a dropdown?
You most likely will be asked about a question about dropdown and selection of values as it is a little tricky and technical as well.
The most crucial detail you must know is that to work with a dropdown in Selenium, it is important to use of the html tag: ‘select’. You cannot handle dropdowns without using the select tag. Have a look at the code below:
<option value=”option3″> Candies</option>
In the above code, an HTML ‘select’ tag is used to define a dropdown element. The ID of the select tag here is myselect. We have given three options in the dropdown: Cakes, Chocolates, and Candies. You can see that each of these choices has an attached value attribute. For instance, for Cake, the value is Option1, for Chocolates its Option2, and for Candies, it is Option3.
To choose a value, you need to:
Identify the ‘select’ html element by using the findelement()
WebElement mySelectElement = driver.findElement(By.id(“mySelect”));
Select dropdown = new Select(mySelectElement);
Pick up an option from that dropdown element.
To pick an option from that dropdown, there are three ways:
dropdown.selectByVisibleText(“Chocolates”); → Choosing an option by the text that is seen.
dropdown.selectByIndex(“1”); → Choosing an option using the Index number of that option.
dropdown.selectByValue(“option2”); → Choosing an option using the value of that option.
Note that in all the cases, the option “Chocolates” is selected from the dropdown. Points 1 and 3 are obvious and point two; we say “1” because the indexing starts from zero.
Read: Top Nagios Interview Questions & Answers
Q.27) How do you hop to a new tab which opens up after you click on a link?
On clicking a link on a web page, you need to use the switchTo() command to change the focus of the Webdriver. Example: driver.switchTo().window();
where ‘windowName’ is the name of the window, you want to switch your focus to.
If you do not have the name of the window, you can use the driver.getWindowHandle() command to fetch the name of all the windows that were initiated by the WebDriver. Remember, it will never give you the names of those windows which Webdriver did not initiate.
On getting the name, you need to run through a loop to get to that window. Here is an example:
String handle= driver.getWindowHandle();
for (String handle : driver.getWindowHandles())
Q.28) How can one upload a file in Selenium WebDriver?
The command element.send_keys(file path) is used to upload a file in Selenium Webdriver. But before you that, you must use the html tag: ‘input’ where the attribute type should be ‘file’. Here is an example to understand it better:
<input type=”file” name=”my_uploaded_file” size=”50″ class=”pole_plik”>
element = driver.find_element_by_id(”my_uploaded_file”)
Q.29) What is the importance of testng.xml?
If you are interviewing for Selenium, you surely know the importance of testing. Selenium does not support the generation of the report as well as test case management. We, therefore, use the TestNG framework with Selenium. It is way advanced compared to Junit, and it is easier to implement annotations making TestNG framework the choice with Selenium Webdriver.
You can define the test suites and grouping of test classes in TestNG, by taking commands from the testing.xml file. It is represented in an XML file and not in a test suite within the testing source code because the suite is a feature of execution. A test suite is a group or collection of test cases.
The testng.xml file should contain the name of all the methods and classes that you wish to execute as a portion of that execution flow.
Some of the advantages of using testng.xml file are:
- It lets the execution of multiple test cases from multiple classes
- It lets the execution of test cases in groups, where a single test can belong to multiple groups.
- It lets parallel execution.
Q. 30) Explain DataProviders in TestNG. Is it possible to call a single data provider method for multiple functions and classes?
One of the advanced selenium interview questions. DataProvider is a feature of TestNG, enabling developers to write DataDriven tests. It supports DataDriven testing, meaning that the same test method can run multiple times with different data-sets. DataProvider is just a method of passing parameters to the test method.
@DataProvider is a method for providing data for a test method. The annotated method must give back an Object where each Object can be allocated to the parameter list of the test method.
Yes. It possible to call a single data provider method for multiple functions and classes. The same DataProvider can be used in several functions and classes by declaring DataProvider in a separate class and then using it again in multiple classes.
Q. 31) What are the features of TestNG?
- Before and after annotations
- XML based test configuration
- Multithreaded execution
- Open API
- Better reporting
- Data-Driven testing
- Dependent Groups.
- Dependent methods
Learn Online Software Development Courses online from the World’s top Universities. Earn Executive PG Programs, Advanced Certificate Programs or Masters Programs to fast-track your career.
Read our Popular Articles related to Software Development
Coming to the end of the Selenium interview questions and answers guide, we hope this helps you get your job. Selenium interview questions for experienced are more technical, but with fierce competition over jobs, it is always great to be prepared well for an interview.
If you are interested in learning Selenium, DevOps and everything about Full Stack development, check out IIIT-B & upGrad’s Executive PG Program in Full Stack Software Development Program.
Which programming language is best for Selenium?
Selenium is one of the most popular portable open-source frameworks designed for the quality assurance of web-based applications. Generally, Selenese is the language used with Selenium, specific to this testing domain. But Selenium also supports the use of other languages for writing test automation scripts. Out of all others, Java and Python are the most preferred languages used with Selenium. Due to its ease-of-use and simple syntax, Python reduces program execution time with Selenium. Plus, with Python API, connecting to a browser becomes very easy. Java is extremely versatile and popular too, and with Selenium, it offers shorter execution times and efficient error handling.
Is Selenium tough to learn?
Selenium is not exactly difficult to learn, but it will take a shorter time to learn it with a properly planned study strategy and discipline. It can be an uphill task when you are learning Selenium entirely by yourself. But when you have the right study roadmap, you can learn the basics of Selenium within a month or so. But before learning Selenium, you need to have an excellent working knowledge of Java or Python and HTML concepts. Selenium with Java or Python is one of the hottest skill sets in demand today. You can find ample resources to learn these technologies and build a lucrative career.
What is the difference between QTP and Selenium?
Both Selenium and QTP are popular tools used for automation testing purposes. While QTP is used for automated functional testing of software applications, Selenium is used for the automated testing of web-based applications. QTP is a licensed tool and expensive, too; it comes with its own built-in repository of objects. QTP offers a higher rate of automation compared to Selenium. However, Selenium is an open-source platform and needs no licenses; users do not incur expenses for this tool. And this offers more flexibility in testing than QTP – it supports different programming languages. Selenium testing scripts can execute across different IDEs, unlike QTP.
What is the highest salary for Selenium Tester?
The highest salary for a Selenium Tester is 15.0 lakhs per annum.
What are the four components of Selenium?
The four components of Selenium are- Selenium IDE Selenium RC Selenium WebDriver Selenium Grid
What are the three major components of Selenium?
The three major components of Selenium include- Selenium WebDriver Selenium Testing Selenium Java
Which language is best for Selenium?
Java and Python are best for Selenium.