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.
Example:
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
driver.navigate().back()
driver.navigate().forward()
driver.navigate().refresh()
driver.navigate().forward()
driver.navigate().refresh()
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
Implicit 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 wait:
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:
To summarize:
Implicit wait time is applied to all elements in your script and Explicit wait time is applied only for 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:
The root element can be located using
Then we can use the .size() to get the number of <li> elements
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
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.
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.
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.
Comments
Post a Comment