Here, we will cover some common selenium interview questions. Selenium WebDriver is a very popular browser automation testing tool and is used by many companies.
When you apply for a job as an automation tester, you are most likely be expected to have experience working with selenium webdriver, so there will be questions at the interview to assess your knowledge of the selenium tool.
Previously, we covered some Test Automation Interview Questions which are focused on the approach to test automation, here the main focus is on selenium tool and what questions you are likely to be asked at an interview.
These selenium interview questions are based on the selenium tutorials.
Selenium Interview Questions
Q#1: What is Selenium?
A: Selenium is a browser based functional test automation tool. It is basically a library which you can use in your program to test a web application. It is important to note that selenium is mainly used for browser automation. It is NOT used for unit testing or API testing.
Selenium Webdriver has many language bindings, which means you can write your tests in your favorite programming language and using the respective selenium bindings.
Q#2: Another interesting selenium interview question is how many languages does selenium WebDriver support?
A: The main ones are: Java, C#, php, Ruby, Python
Q#3: In Selenium WebDriver, how do you select an item from a drop-down menu?
A: We can select an item from the drop-down menu by Value, by Index or by Visible Text.
WebElement cars = driver.findElement(By.id("cars"));
Select car = new Select(cars)
//select by value
car.selectByValue("vo"); //this will select Volvo from drop-down
//select by index
car.selectByIndex(2); //this will select Saab
//select by visible text
car.selectByVisibleText("Audi") //this will select Audi
Q#4: What is the difference between driver.get() and driver.navigate.to()
A: You can use both methods to navigate to a url.
Because navigating to a URL is very common, then driver.get() is a convenient way. However it does the same function as the driver.navigate().to(“url”)
The driver.navigate() also has other functions, such as
Q#5: What is the difference between implicit wait and explicit wait in selenium webdriver?
This question is asked in almost all selenium interview questions because many web applications use AJAX.
A: Selenium Webdriver introduces the concept of waits for AJAX based applications. There are two waiting methods, implicit wait and explicit wait
When an implicit wait is implemented in tests, if WebDriver cannot find an element in the Document Object Model (DOM), it will wait for a defined amount of time for the element to appear in the DOM. In other terms, an implicit wait polls the DOM for a certain amount of time when trying to find an element or elements if they are not immediately available.
Implicit waits can slow down your tests, because once set, the implicit wait is set for the life of the WebDriver object’s instance. This means that when an application responds normally, it will still wait for each element to appear in the DOM which increases the overall execution time.
Another downside is if for example you set the waiting limit to be 5 seconds and the elements appears in the DOM in 6 seconds, your tests will fail because you told it to wait a maximum of 5 seconds.
An example of an implicit wait is:
Explicit waits are better than implicit wait. Unlike an implicit wait, you can write custom code or conditions for wait before proceeding further in the code.
An explicit wait can be used where synchronization is needed, for example, the page is loaded but we are still waiting for a call to complete and an element to appear.
Selenium WebDriver provides WebDriverWait and ExpectedCondition classes for implementing an explicit wait. The ExpectedCondition class provides a set of predefined conditions to wait before proceeding further in the code.
An example of an explicit wait is:
WebDriverWait wait = new WebDriverWait(driver, 10);
Implicit wait time is applied to all elements in your script and Explicit wait time is applied only for a particular specified element.
Q#6: How would you count the number of elements on a page?
This is a common selenium interview question because in many cases you want to click on an item from a list. So it is important to know how to count the elements and select the correct one from the list.
A: We first need to locate the node element where the items are listed. For example, in the html code below:
<li>movie title 1</li>
<li>movie title 2</li>
<li>movie title 50</li>
The root element can be located using
List<WebElement> movies = driver.findElements(By.cssSelector(ul#movies li))
Then we can use the .size() to get the number of <li> elements
int numberOfMovies = movies.size();
Q#7: How can you check if a check-box or a radio button is selected?
A: We can use the .isSelected() method, e.g.
Q#8: Is there a way to do drag and drop in selenium WebDriver?
A: Yes, we can use the following code to do drag and drop
Actions action = new Actions(driver);
WebElement start = driver.findElement(By.cssSelector(“div.source”));
WebElement end = driver.findElement(By.cssSelector(“div.target”));
Q#9: How would you check if an element is visible on the page?
A: We can use isDisplayed() method. The return type of the method is boolean. So if it return true then element is visible otherwise it is not.
Q#10: How to check if a button is enabled on the page ?
A: We can Use isEnabled() method. The return type of the method is boolean. So if it return true then button is enabled else not enabled.
Now that you have gone through these selenium interview questions, it is time to take a short selenium webdriver quiz.