Selenium Automation Testing: Important Interview Question & Answers

Home  >>  Software Testing  >>  Selenium Testing  >>  Selenium Automation Testing: Important Interview Question & Answers

Selenium Automation Testing: Important Interview Question & Answers

On October 3, 2019, Posted by , In Selenium Testing,Software Testing, With 1 Comment

In this article, we have listed the most commonly asked Interview questions as well as their answers for Selenium Automation testing. We have also included the most searched topics in Selenium testing which includes Selenium IDE, Selenium RC, Selenium Grid and Selenium WebDriver interview questions.

Just to inform our students and readers, we keep updating this article with more and more questions and answers as per the latest trends in the job market. Our main goal is to prepare our students and readers job ready.

This is the last tutorial in our Selenium online training series of 30+ comprehensive tutorials. I hope you all enjoyed these tutorials and started learning from it.

1. What is Automation Testing and why we need to go for automation testing

Automation testing is the process of doing testing without any manual intervention. We automate manual test cases using any of the automation tools with any of one programming language.
Why Automation:
• To Save time
• To save money
• Reusable ( we can ran same test cases any number of times like regression testing)
• Error prone human behavior

2. Explain me types of automation testing

We have two types of automation testing

  • Functional Automation: Here automate only functional test cases which basically checks for functionality of application. There are so many tools available for functional automation like QTP, Selenium, VSTS etc..
  • Non-Functional automation (performance testing): As name says we are not checking for functionality but check for performance of the application with respect to response time. Let’s take an example of Gmail application, user enters user id and password and clicks on Login button here we check how much time Gmail is taking to provide response to the user. There are so many tools available for Non-functional automation like Load Runner, JMETER, Silk Performer etc..In Non-Functional OR Performance testing we do below types of testing through automation
  • Load Testing
  • Stress Testing
  • Volume Testing

3. When to go for Automation Testing

We go for automation in below cases

  • When we have a scope for regression testing
  • When application is stable
  • When no frequent changes to application

4. Can you explain me Selenium and futures of Selenium

Selenium is functional automation tool and it is used for automation of functional test cases.
Futures of Selenium:

  • It’s Open source functional automation tool and allows to automate functional test cases
  • Selenium tool allows to automate only web based applications
  • Selenium tool supports compatibility testing like you automate test cases and execute them in any browsers like Chrome, IE etc..
  • We can run test cases any of the operating systems like Windows, Android, IOS, MAC etc…
  • Selenium supports using of multiple languages. It supports below programming languages
    • Java
    • C#
    • Ruby
    • Python
    • Pearl
    • PHP

 

5. How Selenium identifies elements in web page

Every automation tool has its own way of identifying elements in web page. Selenium identifies elements using below properties in the web page:

  • ID
  • Name
  • LinkText
  • Xpath
  • CSS
  • Attribute
  • Tag

 

6. What types of testing supported by Selenium

Selenium supports below types of testing

  • Regression Testing
  • Functional Testing
  • Compatibility Testing

 

7. What is Assertion and why do we use it

Assertion allows you to verify the expected result & actual result. In manual testing we always check for actual and expected result based on which we pass or fail test case. We use assertion to perform same action so that you can pass or fail your test case from automation script.

 

8. What are different types of asserts we have

We have below 2 types of asserts

  1. Hard Assert
  2. Soft Assert

Hard Assert: As said above we use assertions to check actual result and expected result based on which we can pass or fail test case. Let’s say we have automated two test cases (test case 1 & test case 2) and for both the test cases we used hard assertions. If test case 1 fails then it will not execute test case 2 and comes out of execution.

Soft Assert: It’s not like hard assert where even if test case 1 fails it will still continue execution of test case 2. This assert allows to execute all the test cases so that you can continue execution of all the test cases.

 

9.  Challenges you faced while working with Selenium

Below are the challenges faced while working with Selenium

  • Identification element properties are bit tricky and they work in one browser and in another browser same will not work
  • Selenium does not have inbuilt report generation and we have to utilize  third party tools on generation of report
  • No in build object repository like QTP and maintainability of objects bit difficult
  • No proper support as it is open source tool

 

10. What are the different types of XPATH available and what is difference between them

There are two types of XPATH

  • Absolute XPATH
  • Relative XPATH

Absolute XPATH: We go for using absolute XPATH when we try to identify element from root of the node i.e. from HTML tag. Absolute XPATH will always have single slash /

Relative XPATH: This one we use when we try to get XPATH of element from anywhere and it need not to be from root of the node. Relative XPATH always uses double slash. It is always recommended to use relative XAPTH as they are not starting from root. Problem of using with Absolute XPATH is if any new web element is added / removed from root absolute XPATH will fail. But in case of Relative XPATH even new web element added / removed above from root node it will still work.

 

11. Differences between Assert and Verify

Assert: If any test case / step fails assertion marks that test case as fail and stops execution of remaining test case execution and comes of out of execution. In this it will not execute all the test cases if one test case fails

Verify:  It is differ when compared to Assert, Verify will still continue execution even test case / step fails. Here it allows to execution of all the test cases. If test case fails it will mark that test case as Fail and continue execution of remaining test cases.

 

12. What is wait and why do we need to use wait

In any of the automation tool automation script execution should wait until you application page is complete loaded. All most all of the automation tools we always face issues as application response time and script execution are not in synch.

To avoid this synchronization issues we have to use wait in all most all the automation tools.

 

13. What are the different wait’s available in Selenium

In Selenium we have below waits:

  • Implicit wait
  • Explicit wait
  • Fluent wait

 

14. Differences between implicit wait and explicit wait

Implicit wait: It basically one of wait which makes your automation script to wait until all elements are loaded in your application page. Here we can set specific time and your script execution will wait for specified time. This wait is applicable for entire page level and not specific for any field. If page is not loaded on specified time, your script execution will start and it may lead to fail your script as complete page itself is not loaded.

Explicit wait: As the name says “Explicit” this wait allows to setup a wait time on a specific field. It’s not like implicit wait which was at page level. Let’s take an example to understand better.

Let’s say I have application in which I have two fields like “Country” and “Province” Once I select country as India and province drop-down should load with all provinces of India. Here it will take some time for province to refresh and load for data. So here I can use explicit wait on only province field so that my script can wait until all the data is loaded on province field.

 

15. What is Fluent wait

Fluent wait allows setup a wait for a specific condition and frequency as well. Frequency allows to setup how frequently your script should check whether element  is present or not. Like it will keep check for element presence as per the frequency time is given.  Let’s take an example to understand better

Let’s say, one of the element in your application is taking some time for presence of that element and keep changing sometimes it takes 20 seconds and sometimes 30 seconds. So in this example we can go for using fluent wait as it will keep check for element presence as per the frequency time given.

 

16. Can I use Thread.Sleep() method for wait

Thread.Sleep() method is from Java and it is a static wait. It is not recommended to use this method as it is not dynamic wait.

 

17. What is difference between findElement() and findElements()

As discussed in of the above question “How Selenium identifies elements in web page” we need to identify the element on the web page in order to perform any action on that element. findElement and findElements are the two different methods which are used to find the element / elements on your web page. These two methods are from class “WebElement”.

findElement() method is used to find one element on your web page. If there are multiple elements are matching for the xpath you have given to find by default it will return first element. If no element found with given xpath then this method will return “NoSuchElementException”.

fndElements(): This method will return list of web elements where as findElement() method will return only one element. If element not found for given xpath then it will written empty list and not an exception. Where as in case of findElement() method it will return “NoSuchElementException”

 

18. What is object repository and why we need this

Object repository is the place where we store all object element properties here. It’s centralized place where we story entire application web elements properties in this place and all the test cases will use this.

 

19. How do you type a value in text field of your application using Selenium

As part of automation we always have to enter some data in text fields and we use an existing method “sendKeys” for this. We always use this sendKeys method along with findElement method as we have to specify to which field we need to send data.

Below is example if you want to send data for first name filed:

driver.findElement(By.name(“firstname”)).sendKeys(“Ashok”);

 

20. How do you select a value from drop-down / pick list using Selenium

If want to select a value from drop-down / pick list we have an existing class called Select in Selenium and it contains lot of methods to perform actions on drop-down / pick list. In order to select a value from drop-down / pick list we have below two methods in Select class

  • selectByVisibleText(): This method allows to select a specific value with exact name. Let’s say I have a drop-down called “Country” and would like to select country as “India” then I would write it as selectByVisibleText(“India”) and it select “India” as value for field country.

 

  • selectByIndex(): This method allows to select a specific value with index number.  Let’s say I have a drop-down called “Country” and would like to select a value from country which at 10th position then I would it as selectByIndes(10) and it selectswhatever the value stored as 10th positing in field country.

21. How do you find element which is in Frame

In order to identify element and perform some action, which is in Frame, first we need to switch to Frame and perform action on specific element

 

22. How do you switch to Frame

To switch to Frame we have existing method “driver.switchTo().frame()” and this method allows to switch to frame. We can switch to frame using either of below

  • Get frame id and pass this id as a parameter to above method
  • Get frame name and pass this name as a parameter to above method

You can even get the index number of the frame and pass this index number to above method.

23. How do you come out of frame after performing action in the Frame

We have existing method defaultContent() which takes you out of the Frame.

 

24. How do you switch between windows using Selenium

We have couple of web-based application, which have many windows like when I click on a link it opens in new window. If I have to perform action on newly opened window, I have to switch to newly opened window. Selenium allows switching between windows using “driver.switchTo().window()” this method allows to switch from one window to another window.

 

25. What is difference between getWindowHandle() &getWindowHandles()?

Selenium identifies window which opened by automation script with unique id. This id will have new value if you open another window and it goes on.

getWindowHandle() will return this handle (id) of the window on which it is currently running. It allows to work with single window and returns Stinr

getWindowHandles() will return all handles(id’s) of windows which are opened by your automation script so that you can handle multiple windows. This method will return Set<string>

We can use SwitchTo().Window(“handle”) to switch to the window which you want OR If you know window id you can use SwitchTo().Window(“windowID”)

26. How do you open the browser and type your application URL

We have below two methods which can be used for opening the browser and type application URL after opening the browser

  • get()
  • navigate()

27. Difference between driver.get() and driver.navigate()

Driver.navigate() will tack the history where asdriver.get() will not. Driver.navigate()allows to perform actions like

driver.navigate().forward(): It’s like clicking on “forward” button in the browser.

driver.navigate().back():It’s like clicking onon “back” button in the browser.

 

28. How do you handle pop-up windows

In Webdriver we have existing class “Alert” and it has lot of methods to handle alert windows. Before performing any action on alert window first we need to switch to alert window. We can do this using Alert alert= driver.switch().alert().

 

29. How do you perform actions on alert window

We can perform below actions on alert window

  • Click on OK button from alert window
  • Click on Cancel button from alert window
  • Get text that is displayed on alert window

We can use below methods from Alert class to perform above actions

Let’s say we declare this Alert alert= driver.switch().alert().

  • To click on OK button we use alert().accept()
  • To click on Cancel button we use alert().dismiss()

To get text displayed on alert window we use alert.getText()

 

30. Can you explain me where and all you can use Explicit Wait

We can use explicit wait on following

  • IF you want wait for element to be clickable then we can use elementToBeClickable()and it waits for an element to be clickable like it should be present/displayed/visible on the screen and also it is enabled.
    Example: wait.until(ExpectedConditions.elementToBeClickable(By.xpath(“//div[contains(text(),’Send’)]”))). Here it waits for “Send” button to be present and to be clickable.
  • IF you want wait for text to be present then we can usetextToBePresentInElement() –and it waits for an element having a certain text to be presentable.

Example:
wait.until(ExpectedConditions.textToBePresentInElement(By.xpath(“//div[@id= ‘resetpin’”), “text to be found”)). Here it waits for an element with text “resetpin” is appeared

  • IF you want to wait until alert window ispresent then we can use alertIsPresent()-and it waits waits for an alert box to appear.

Example:
wait.until(ExpectedConditions.alertIsPresent()) !=null). Here it waits until alert window is present.

  • If you want to wait until for a page with some expected title then we can usetitleIs()– and it waits for a page with anexpected title.

Example:
wait.until(ExpectedConditions.titleIs(“yahoo”)). Here it waits for an element with title “yahoo” is appeared

  • If you want to wait for a frame to be available and then switch to framethen we can useframeToBeAvailableAndSwitchToIt()– it waits for a frame to be available and then immediate after the frame is available it switches to it automatically.

Example:
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id(“frameid”))). Here it waits for a frame is available and then switches once it is available.

One response to “Selenium Automation Testing: Important Interview Question & Answers”

Leave a Reply

Your email address will not be published. Required fields are marked *