Must know questions and answers before your selenium interview!
March 19, 2021. 20 min read.
Selenium is a well-heard name in the world of automation testing. With standout features to automate web applications, it is one of the most popular tools in quality assurance and testing.
With easy implementation, re-usability of codes and any-time automated testing from remote locations, Selenium has come to the fore.
You See! Automation is favorite among industry people, at least law of least effort says so!
Quality analysts are on high demand because whatever the state-of-art web applications are being built needs quality assurance and expert testing.
In a real-world scenario, where client service takes paradigm, any kind of inefficiency or lag in the performance of web application can seriously derail the brand's credibility and lead to losses in business.
A system which is getting updated on a regular basis with new features needs to be consistently tested under novel circumstances so that they do not falter in real situations.
Manual quality testing has taken a backseat and hiring managers need talented quality analysts to come up with innovative automated testing methods to test their web application under a myriad of situations.
Yes, you can be one of those aspiring Quality analysts and you have got it in you!
Even if you are anxious about your chances of job and don't know where to start, what to do, how to do I would say…
Relax, take a deep breath and start thinking with a clear mind.
Chart out your course of action.
It is never too late. Anything can be achieved through passion and perseverance.
To help you out, I have prepared 74 selenium interview questions, many of which are most common questions asked in selenium interview.
Through these selenium interview questions, what I aim for is the revision of core concepts of selenium, such as its core functionalities, important properties, commands as well as its standard operations.
After attempting and preparing for these selenium interview questions, I am sure you will gain a lot of confidence on your preparation and you will be able to answer the interviewers with equal confidence :)
"Far and away the best prize that life offers is the chance to work hard at work worth doing."
– Theodore Roosevelt
Let's go through this journey of some of the most common selenium interview questions whose answers, industry guys expect you to know about!
Ans: Selenium is an open-source project to perform automation tests on web applications. It provides a user-friendly interface to write test scripts in a variety of languages such as Python, Java, C# which can then be automatically run to check upon core functionalities of application under various environments.
Ans: WebDriver API'S used for automating browsers are:
Ans: Browsers supported by selenium are:
• Internet Explorer
• Google Chrome
Operating systems supported by Selenium are:
Ans: Selenium suite components are:
• Selenium IDE: It is one of the tools of selenium software which is used for creating automatic test cases for web applications. Provides a graphical user interface for storing user interactions with the web application.
• Selenium Remote Control: It is a testing framework used for writing test cases in any programming language to automate testing for web applications against browsers.
• Selenium WebDriver: It is an open-source collection web APIs used for automating web application testing. Here also we can develop test scripts in any language. It is different from Selenium Remote Control as it has simpler architecture, easier to use commands and does not require an additional server.
• Selenium Grid: It is used for simultaneous execution of the tests across various browsers and operating systems. This is achieved by routing the commands to remote browser instances where one server acts as a single hub.
Ans: Different types of Junit annotations are:
• @Test: It declares that the method attached to it can be run as a test case.
• @Before: It allows the method to execute before the execution of each test method.
• @After: It allows the method to execute after each test method execution.
• @BeforeClass: It allows the method to be executed before running of test methods in the current class.
• @AfterClass: It allows the method to be executed after running of test methods in the current class.
Ans: Selenium WebDriver supports various programming languages such as:
Ans: During automated testing, several web elements may face time lag for loading on the web server and they may occur at different intervals on a webpage. To tackle such issues, Wait commands direct test scripts to wait for a specified time interval before throwing an exception.
In this way, Wait assists the execution of the test cases by improving flexibility of testing.
The next question is one of the frequently asked selenium interview questions.
Ans: Different types of Waits present in Selenium are: -
• Implicit Wait
• Explicit Wait
• Fluent Wait
The difference between Implicit and Explicit Wait is that in Implicit Wait we specify a particular time for the system to wait between two subsequent test cases before starting for the next test case. But in Explicit Wait, we mention the maximum time to wait or a condition which is required to be met, until which system remains in the condition of halt.
Explicit Wait is specified for a particular instance while Implicit Waits are specified across the whole test script.
Ans: findElement() returns a single web element from a page. It returns first matching web element on the page while findElements() returns a list of all matching web elements on the page.
Ans: Selenium 2.0 is a further extension of Selenium where original Selenium project is merged with the WebDriver project.
While selenium is good with supporting common test cases, WebDriver brings with itself efficient browser driver implementations and object-oriented API.
With Selenium 2.0, cross web browser testing can be done in multiple languages.
Ans: Selenium 3.0 is the modified version of Selenium 2.0 with many changes implemented in core functionalities.
Selenium RC which was there in Selenium 2.0 has been removed and instead, it has been replaced by WebDriver completely in Selenium 3.0.
Selenium 3.0 is the combination of Selenium IDE, Selenium WebDriver and Grid.
Ans: Selenese is a set of commands in selenium which are used for running the tests. There are 3 types of Selenese commands:
• Actions: These are the commands which change the state of applications. For example: selecting an option, clicking on a link.
• Accessors: These commands are used for checking the state of variable and storing the result values in a variable.
• Assertions: They are used as checkpoints to ensure the state of applications conforms to the expected state.
Ans: setSpeed() is a method which specifies a delay time before the execution of every Selenium operation while thread.sleep() method when implemented will wait for only once.
For example: - If there are multiple operations present in a script then setSpeed() on implementing once will set delay time for every operation present in the script but for the same requirement of delaying each operation, we will have to implement thread.sleep() before every operation.
Ans: To switch between frames you can use switchTo() method.
For using switchTo() method first we will create an instance of the next frame like this
WebElement delta = find.ElementById("next_frame") ;
Then we will apply switchTo() method by incorporating that instance of frame as shown below
Ans: Limitations of Selenium are:
• It cannot support window and mobile applications on its own. To do that Selenium has to be integrated with a third-party tool like TestNG.
• It has less accuracy when dealing with dynamic web elements.
• It does not automate captchas and barcodes.
• It does not support image testing
• It doesn't support test management and has no in-built reporting.
Ans: To handle multiple windows, we can use window handle features present in selenium. Some of these features are:
• getwindowhandle(): used for returning the window handle of the current webpage.
• getwindowhandles(): used for returning a set of handles of all opened webpages.
• action: a class which consists of the methods to perform certain operations on webpages such as drag and drop.
• switchTo(): used for switching from one window to another window.
Ans: TestNG is an open-source testing framework which is used for building powerful and flexible tests using annotations, groupings, sequencing and inculcating parameters. It is inspired by JUnit which is another testing framework. TestNG is better than JUnit as:
• It has advanced and easier annotations.
• Parallel execution of test scripts across various machines.
• Test cases can be formed into groups and prioritised.
Ans: Some of the frequently used TestNG annotations are:
Ans: Other automation tools which are there apart from Selenium are:
• Katalon Studio
• IBM Rational Functional Tester
Ans: Action class methods are generally involved in drag and drop operation. Two methods used are: -
• Action.dragAndDrop(Sourcelocator, Destinationlocator): In 1st argument, you need to fill element to be dragged and in 2nd argument, you need to fill the element on which to drop the first element.
• Action.dragAndDropBy(Sourcelocator, x-axis pixel of Destinationlocator, y-axis pixel of Destinationlocator): Here in the first argument we need to fill element which is to be dragged.
• In 2nd argument, you need to fill the x-axis pixel value of the 2nd element upon which to drop the 1st argument's element.
• In 3rd argument, you need to fill y-axis pixel value of the 2nd element on which the 1st argument's element is going to be dropped.
Next question is also one of the frequently asked selenium interview questions.
Ans: Some of the different types of navigation commands are:
• navigate().forward(): Used for going to next webpage in the web browser's history.
• navigate().backward(): Used for going to the previous webpage in the web browser's history
• navigate().refresh(): Used for refreshing the current webpage
• navigate().to(): Used to go directly to the specified website by mentioning it's URL as an argument inside the "to" method of navigate().
Ans: To submit a form you can use the following syntax as shown here:
where we want to submit the form through the element.
Another common method is to use the click() method on the element which is involved in the form submission.
Ans: Different test types supported by Selenium are:
• Quick Build
Ans: There are 40+ different exception encountered in Selenium are but here I am mentioning few popular ones:
• NoSuchElementException: It occurs when we try to get elements from empty list/array or when we have reached the end of the array and are still trying to get the element.
• NoSuchWindowException: It occurs when the driver is switching from the current window to a non-existent window.
• NoSuchFrameException: It occurs when the driver is not able to find a valid frame to switch to from the current frame.
• NoAlertPresentException: It occurs when the driver is not able to find Alert on the webpage to switch to.
• WebDriverException: It occurs when WebDriver is unable to get initialized by code entered.
• ElementNotVisibleException: It occurs when an object is present in DOM but isn't visible.
Ans: Selenium is the software which can handle only web applications for automated testing. It does not handle window-based or mobile-based applications.
For Selenium to handle Windows-based popups, you have to add additional tools such as AutoIt and RobotClass. AutoIt is a free software which can automate the mouse movements and the keystrokes while RobotClass is used for creating native system inputs for the automated testing, self-running demonstrations in applications which require control over mouse and keyboard.
Ans: XPath is a locator technique used for navigating through the XML or HTML structure of the documents.
It helps us in dynamically identifying the elements in the webpage
Web elements can be located using two types of X-paths:
• Absolute XPath
• Relative XPath
Ans: To launch the browser using WebDriver on your operating system you need to write the following syntax:
• For internet explorer WebDriver driver = new InternetExplorerDriver() ;
• For Chrome WebDriver driver = new ChromeDriver() ;
• For Firefox
WebDriver driver = new FirefoxDriver() ;
Hey, wanna learn Webdriver from best of the courses! Check this out!
Ans: Following methods can be used for checking the visibility of elements on the screen:
Syntax: boolean ispr = driver.findElement(By.id("__")).isDisplayed
Syntax: boolean ispb = driver.findElement(By.id("__")).isSelected
Syntax: boolean ispc = driver.findElement(By.id("__")).isEnabled
Ans: driver.close() closes only the current working browser window while driver.quit() command closes down all the related window browsers, tabs and popups apart from the current working browser.
Ans: Benefits of Automation testing are:
• Able to perform tests across multiple machines simultaneously
• Maximizes test coverage
• Reusable test scripts
• Test cases can be scheduled to execute by themselves from any place, even if it is remote.
• Lengthy and complex test cases can be performed in an error-free way by developing appropriate test scripts.
Ans: To submit forms, you can use 'submit' method on the element as shown here
Ans: Hard Assert is a type of assertion which raises an exception immediately when an assertion statement fails and goes forward with the next test case in the test suite.
Ans: Soft Assert is a type of assertion which do not raise an exception on assertion failure. It instead collects errors in the test case and carries on with the execution of the next test case.
Ans: Browser webpage can be refreshed in many ways-
• By using driver.getCurrentUrl() or driver.get("URL")
• By using driver.navigate().to("URL") on the current URL
• By using driver.navigate().refresh() command
Next two questions are common selenium interview questions based on the page object model
Ans: POM is a testing framework in which for each page of the application a separate class is created where all the web elements corresponding to that webpage along with their methods are kept. The test script is separately created from that page object file and methods of page object file are then called upon from the test scripts.
In this way, if any changes in methods as such required for testing, can be done on page object file where that method is stored instead of doing those method changes through the entire test scripts.
Ans: Advantages of the POM are:
• Once we have written a code, we can reuse the code for multiple other tests.
• Readability of code becomes easy as there is a clear separation between the test code and the page code.
• Any changes in the user interface can be updated and maintained in Page Objects and Classes.
• Lesser code duplication and easier test maintenance
Ans: Hub is the central point in the selenium grid which receives the test request from multiple servers and it triggers those tests cases into multiple servers.
Ans: Nodes are instances of selenium grid which execute test cases loaded in the hub.
Nodes are responsible for the simultaneous running of the test cases in different browsers across multiple machines.
Ans: driver.getWindowHandle() returns a single handle of the current window/tab while driver.getWindowHandles() returns set of handles of all the existing windows/tabs.
Apart from that, the return type of getWindowHandle() method is a string while that of getWindowHandles() is a set of strings.
Ans: To create a dropdown, you first need to create a 'select' tag.
Let's say you have to choose a flavour of an ice-cream from 'chocolate', 'vanilla' and 'strawberry'. So first I create an HTML tag 'select' with id as 'SelectFlavour'. The code for it is:
<select id = "SelectFlavour" >
Then to add options for dropdown, I attach attribute 'value' to each option which I have prepared. Now I implement following codeNext question is again one of the popular selenium interview questions.
Ans: To select an option from dropdown we use Select class.
WebElement myelement = driver.findElement(By.id(string text))
Select choose = new Select(myelement)
To select an option from dropdown we can do it in many ways:
• choose.selectByVisibleText(string text)
• choose.selectByIndex(int index)
• choose.selectByValue(string value)
Ans: Breakpoints are used to pause the execution of test scripts in between so that we can check whether the code is working according to our expectations or not. They are used for debugging the code in the test script.
Start points can be used for starting the execution of tests from anywhere inside the test script. Start point tells us from where should testing begin.
We can use it to start from the middle of the program or just after the breakpoint.
Ans: To insert a breakpoint, right-click on the command and select 'Toggle Breakpoint'.
For the same, you can also press shortcut key 'B' to insert a breakpoint.
For deselecting a breakpoint, the same procedure can be applied.
Ans: Object Repository is a place where the elements belonging to Application Under Test (AUT) are stored with a locator value associated with them. During running of tests on the application, these locators identify web elements in the webpage.
Hence it acts as an interface between the test script and application to identify objects during the execution of tests.
Ans: Some of the locators present in Selenium are: -
1) ID 2) Name 3) Attribute 4) CSS 5)Linktext 6)XPath
Every element present in the webpage can be associated with either of the locators mentioned above and hence we can find the elements by using them.
Ans: Page Factory is a class belonging to the Page Object framework which helps in handling the 'Page Object' more efficiently.
This is done using @Find annotation and initElements method.
@Find is used for locating the web elements by passing their attribute as a parameter.
initElements is used for initialization of web elements mentioned in the Page classes.
Ans: Differences between CSS and Xpath are:
Ans: Desired Capabilities is a class present in Selenium which stores aspects of browser in form of key-value pairs. These capabilities are then used to set properties of the browser.
In this way, we can easily test the performance of the browser in terms of these properties.
Ans: Some of the test cases which can be automated are:
• Regression test cases
• Cross-browser tests
• End-to-End test cases
• Integration tests
• Functional cases
Ans: No, since it only does web application testing.But we can still perform database testing by establishing the connection between JDBC (Java Database Connectivity) API and Selenium and then integrating with TestNG.
Ans: You can use the below-mentioned method to navigate to the new window.
driver.navigate().to (URL of new window)
Ans: Different types of test automation framework are: -
• Data-Driven Framework
• Keyword-Driven Testing Framework
• Hybrid Testing Framework
• Behaviour-Driven Testing Framework
• Modular Testing Framework
Ans: In the data-driven framework, the data associated with the test script is not stored in the test script but is stored outside such as in Excel, CSV file etc.
During testing of the application, the input and output values are fetched from these outside files.
The main advantages of this framework are: -
• Despite changes in the test script, data for testing remains unaltered.
• Code can be used again and again leading to fast and efficient testing.
• Myriad of situations can be tested by changing data on our own.
Ans: In the keyword-driven framework, the test scripts are created in form of 'keywords'. The main role of 'keywords' which are stored in the excel file, is that it initiates the execution of the code for those functions which are going to be tested.
It takes values from the data stored in a separate file, runs the script and stores the output in the excel sheet.
Ans: Hybrid framework as the name suggests is hybrid of both data-driven framework and keyword-driven framework.
It entails the properties of both frameworks. Hybrid framework stores the input and output data in a separate file and keywords in a separate excel file.
These objects are then invoked in test cases via test script during testing.
Ans: Fluent Wait is used to define the maximum amount of time to wait before checking on the condition and number of times to check the condition before throwing an exception.
Basic Syntax: -
Ans: Parameters that you have to pass in Selenium are:
• Port Number
Ans: To upload a file in the WebDriver, you will have to pass the path to file inside the sendKeys() as an argument.
For example: -
No, Captcha can't be automated in Selenium.
The purpose of Captcha is to prevent automated programs and bots from accessing sensitive information.
Automation Test Engineers will have to manually enter the captcha by themselves.
Ans: To delete cookies we can use following statements: -
• manage().deleteCookie(arg0): To delete specific cookie
• manage().deleteCookieNamed(arg0): To delete cookies by name
• manage().deleteAllCookies(): To delete all cookies
Ans: Assertion is basically a set of validation statements which are used to check the functionality of test cases in applications. They are used in web applications to check whether they are working as per expectations or not.
Different types of assertions are 1) assert(), 2) verify(), 3) waitFor()
Ans: SearchContext is the super interface of the WebDriver.
Ans: Some of the methods of Robot Class() are:
• mousePress(): This method is used to pressing the left button of mouse.
• keyPress(): To press any key, this method can be invoked.
• mouseRelease(): To release one or more mouse buttons, you can use this method.
• keyRelease(): To release the pressed key on the keyboard, use this method
Ans: We can get the height and the width of the text box using following commands: -
• driver.findElement(By.xpath("textbox's xpath")).getSize().getWidth()
• driver.findElement(By.xpath("textbox's xpath")).getSize().getHeight()
Ans: Some of the web drivers supported for Mobile Testing drivers are:
• Android driver
• I Phone driver
Ans: Automation tools used for functional testing are:
• Coded UI
• Rational Robot
• Auto It
Ans: WebDriver Manager is a dependency which is added into the path, so that whatever drivers are required for browsers are automatically downloaded, thus sparing us from the effort to download each driver manually for a particular browser.Thus, it is used for maintaining driver's executables and it supports various browsers such as Firefox, GoogleChrome, Opera, Edge etc.
Ans: driver.navigate.to() and driver.get() are both used for switching to specific webpage by mentioning the URL as a parameter but there are some differences between them which are mentioned below: -
Ans: Different mouse commands which can be performed using action class are: -
• dragAndDrop(source locator, destination locator): Used for dragging a web element onto another web element.
• dragAndDropBy(source locator, x-pixel of destination locator,y-pixel of destination locator): Same as that of dragAndDrop just that we pass pixel values of the dragged element instead of an instance of that element.
• click(): Used for clicking an element.
• doubleClick(): For double-clicking an element.
• clickAndHold(): To click an element without releasing it.
• moveToElement(): Shifts the mouse to the element's centre.
Ans: To get the attribute of an element you can use the getAttribute() method.
General syntax (For Java):
element.getAttribute("name of attribute")
Finally, we come to the end of the journey of selenium interview questions. I am sure that you must have got a good idea of what to expect in terms of questions which can be asked in the interview.
But more than that, I want you to get comfortable with the idea of the interview.
You may have the skillsets, you may be well-versed with selenium, having a standout resume to impress hiring managers.
Even then an interview tests you on a lot of aspects which aren't related to your technical knowledge. They test you on quick decision making, approach to problem solving and applications of concepts which you have developed over time.
To be able to perform well on these metrics requires calmness and confidence which comes from well preparedness and loads of practice.
You can check out a plethora of MOOC's available on Selenium. Explore them! Learn whatever suits you best and if you find any difficulty in choosing the right courses, you can check out on Edvicer. It aggregates, compares, and recommends the most appropriate learning resources!
Once you start learning new skills related to your interest, apply those skills by doing a real-time project. Projects are the best platform to polish your skills, they help you go into the depths of the application of your new-found skills.
After learning those skills and doing some projects, you can start your hunt for internships and employment opportunities. You can, once again check out Edvicer! We also aggregate several internships and job opportunities on our platform. You can truly find everything you need here!
Now that you have everything to start, its time you get down and start exploring the long way. We wish you the best and hope that you found this useful. We love to help people find their way in picking up a new skill and would love to hear from you as well.
Thank you, and all the best!
Subscribe to our newsletter to get updates on interesting articles.
Edvicer Interview Series | Episode 1 | Mr Kunal Kini - Full ...
By Vineet Nayak
July 29, 2020
10 min read
Through this series, Edvicer aims to share the journey & experience of successful people across seve...
Top 50 Spring Boot Interview Questions & Answers
By Satyam Ranjan
January 29, 2021
20 min read
Must know questions and answers before your spring boot interview!...
Top 50 DBMS Interview Questions & Answers
By Satyam Ranjan
February 11, 2021
20 min read
Must know questions and answers before your dbms interview!...
Top 50 Networking Interview Questions & Answers
By Anjali Thacker
February 18, 2021
15 min read
Must know questions and answers before your networking interview!...
Top 50 Digital Marketing Interview Questions & Answers
By Anjali Thacker
March 3, 2021
15 min read
Must know questions and answers before your digital marketing interview!...
Subscribe to our newsletter to get updates on interesting articles