1. What is Automation Testing? Automation testing is the process of testing the software using an automation tool to find the defect...

Selenium Interview Questions



1. What is Automation Testing?
Automation testing is the process of testing the software using an automation tool to find the defects. In this process, executing the test scripts and generating the results are performed automatically by automation tools. Some most popular tools to do automation testing are HP QTP/UFT, Selenium Web Driver, etc.,
2. What are the benefits of Automation Testing?

1.  Saves time and money. Automation testing is faster in execution.
2.  Reusability of code. Create one time and execute multiple times with less or no maintenance.
3.  Easy reporting. It generates automatic reports after test execution.
4.  Easy for compatibility testing. It enables parallel execution in the combination of different OS and browser environments.
5.  Low-cost maintenance. It is cheaper compared to manual testing in a long run.
6.  Automated testing is more reliable.
7.  Automated testing is more powerful and versatile.
8.  It is mostly used for regression testing. Supports execution of repeated test cases.
9.  Minimal manual intervention. Test scripts can be run unattended.
10. Maximum coverage. It helps to increase the test coverage.

3. What are the challenges and limitations of Selenium WebDriver?
As we all know Selenium WebDriver is a tool which automates the browser to mimic real user actions on the web. Selenium is a free open source testing tool. Some of the challenges with selenium WebDriver are as follows
1.  We cannot test windows application
2.  We cannot test mobile apps
3.  Limited reporting
4.  Handling dynamic Elements
5.  Handling page load
6.  Handling pop-up windows
7.  Handling captcha


4. What type of tests have you automated?

Our main focus is to automate test cases to do Regression testing, Smoke testing, and Sanity testing. Sometimes based on the project and the test time estimation, we do focus on End to End testing.
5. How many test cases you have automated per day?
It depends on Test case scenario complexity and length. I did automate 2-5 test scenarios per day when the complexity is limited. Sometimes just 1 or fewer test scenarios in a day when the complexity is high.
6. What is a Framework?
A framework defines a set of rules or best practices which we can follow in a systematic way to achieve the desired results. There are different types of automation frameworks and the most common ones are:
·        Data Driven Testing Framework
·        Keyword Driven Testing Framework
·        Hybrid Testing Framework

7. Why do you prefer Selenium Automation Tool?
1.  Free and open source
2.  Have large user base and helping communities
3.  Cross-browser compatibility
4.  Platform compatibility
5.  Multiple programming languages support

8. What is Selenium?
Selenium is an open source (free) automated testing suite to test web applications. It supports different platforms and browsers. It has gained a lot of popularity in terms of web-based automated testing and giving a great competition to the famous commercial tool HP QTP (Quick Test Professional) AKA HP UFT (Unified Functional Testing).
Selenium is a set of different software tools. Each tool has a different approach in supporting web based automation testing.
It has four components namely,
  • Selenium IDE (Selenium Integrated Development Environment)
  • Selenium RC (Selenium Remote Control)
  • Selenium WebDriver
  •  Selenium Grid

9. What is Selenium IDE?
Selenium IDE (Integrated Development Environment) is a Firefox plugin. It is the simplest framework in the Selenium Suite. It allows us to record and playback the scripts. Even though we can create scripts using Selenium IDE, we need to use Selenium RC or Selenium WebDriver to write more advanced and robust test cases.
10. What is Selenese?
Selenese is the language which is used to write test scripts in Selenium IDE.
11. Which is the only browser that supports Selenium IDE to be used?
Firefox
12. What is Selenium RC?
Selenium RC AKA Selenium Remote control / Selenium 1. Selenium Remote Control was the main Selenium project for a long time before the WebDriver merge brought up Selenium 2. Selenium 1 is still actively supported (in maintenance mode). It relies on JavaScript for automation. It supports Java, JavaScript, Ruby, PHP, Python, and Perl and C #. It supports almost every browser out there.
13. What is Selenium WebDriver?
Selenium WebDriver AKA Selenium 2 is a browser automation framework that accepts commands and sends them to a browser. It is implemented through a browser-specific driver. It controls the browser by directly communicating with it. Selenium WebDriver supports Java, C#, PHP, Python, Perl, Ruby.
14. What is Selenium Grid?
Selenium Grid is a tool used together with Selenium RC to run tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines running different browsers and operating systems.
In simple words, it is used to distribute your test execution on multiple platforms and environments concurrently.
15. When do you use Selenium Grid?
Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution
16. What are the advantages of Selenium Grid?
It allows running test cases in parallel thereby saving test execution time.
It allows multi-browser testing
It allows us to execute test cases on multi-platform
17. What is a hub in Selenium Grid?
A hub is a server or a central point that controls the test executions on different machines.
18. What is a node in Selenium Grid?
Node is the machine which is attached to the hub. There can be multiple nodes in Selenium Grid.
19. What are the types of WebDriver APIs available in Selenium?
·        Firefox Driver
·        Gecko Driver
·        Internet Explorer Driver
·        Chrome Driver
·        HTML Driver
·        Opera Driver
·        Safari Driver
·        Android Driver
·        iPhone Driver
·        EventFiringWebDriver

20. Which WebDriver implementation claims to be the fastest?
The fastest implementation of WebDriver is the HTMLUnitDriver. It is because the HTMLUnitDriver does not execute tests in the browser.
21. What are the Programming Languages supported by Selenium WebDriver?
·        Java
·        C#
·        Python
·        Ruby
·        Perl
·        PHP

22. What are the Operating Systems supported by Selenium WebDriver?
·        Windows
·        Linux
·        Apple

23. What are the Open-source Frameworks supported by Selenium WebDriver?
·        JUnit
·        TestNG

24. What are the Locators available in Selenium?
Different types of locators are:
1.  ID
2.  ClassName
3.  Name
4.  TagName
5.  LinkText
6.  PartialLinkText
7.  XPath
8.  CSS Selector

25. What is an XPath?
XPath is used to locate the elements. Using XPath, we could navigate through elements and attributes in an XML document to locate web elements such as textbox, button, checkbox, Image etc., in a web page.
26. What is the difference between “/” and “//” 
Single Slash “/” – Single slash is used to create XPath with absolute path i.e. the XPath would be created to start selection from the document node/start node.
Double Slash “//” – Double slash is used to create XPath with relative path i.e. the XPath would be created to start selection from anywhere within the document.
27. What is the difference between Absolute Path and Relative Path?
Absolute XPath starts from the root node and ends with desired descendant element’s node. It starts with top HTML node and ends with input node. It starts with a single forward slash (/) as shown below.
Relative XPath starts from any node in between the HTML page to the current element’s node (last node of the element). It starts with a double forward slash (//) .
28. What is the difference between Assert and Verify in Selenium?
Assert: In simple words, if the assert condition is true then the program control will execute the next test step but if the condition is false, the execution will stop and further test step will not be executed.
Verify: In simple words, there won’t be any halt in the test execution even though the verify condition is true or false.
29. How to launch a browser using Selenium WebDriver?
WebDriver is an Interface. We create an Object of a required driver class such as FirefoxDriver, ChromeDriver, InternetExplorerDriver etc.,
To launch Firefox Driver:
WebDriver driver = new FirefoxDriver();
To launch Chrome Driver:
WebDriver driver = new ChromeDriver();
To launch Internet Explorer Driver:
WebDriver driver = new InternetExplorerDriver();
30. Is the FirefoxDriver a Class or an Interface? 
FirefoxDriver is a Java class, and it implements the WebDriver interface.
31. What is the super interface of WebDriver?
SearchContext.
32. Explain the line of code Webdriver driver = new FirefoxDriver();?
WebDriver is an interface and we are creating an object of type WebDriver instantiating an object of FirefoxDriver class.
33. Why do we create a reference variable ‘driver’ of type WebDriver
If we create a reference variable driver of type WebDriver then we could use the same driver variable to work with any browser of our choice such as IEDriver, SafariDriver etc.,
34. What are the different exceptions you have faced in Selenium WebDriver?
Some of the exceptions I have faced in my current project are
1.  ElementNotVisibleException
2.  StaleElementReferenceException

Element Not visible Exception:
This exception will be thrown when you are trying to locate a particular element on webpage that is not currently visible even though it is present in the DOM. Also sometimes, if you are trying to locate an element with the XPath which associates with two or more element.
Stale Element Reference Exception:
A stale element reference exception is thrown in one of two cases, the first being more common than the second.
The two reasons for Stale element reference are
1.  The element has been deleted entirely.
2.  The element is no longer attached to the DOM.

We face this stale element reference exception when the element we are interacting is destroyed and then recreated again. When this happens the reference of the element in the DOM becomes stale. Hence we are not able to get the reference to the element.
Some other exceptions we usually face are as follows:
·        WebDriverException
·        TimeoutException
·        NoAlertPresentException
·        NoSuchWindowException
·        NoSuchElementException
·        TimeoutException

35. How to Login Into Any Site If It Is Showing Any Authentication Pop-Up for Username and Password?
To do this we pass username and password with the URL
http://username:password@url
e.g. http://myUserName:myPassword@gmail.com

36. What are the types of waits available in Selenium WebDriver?
In Selenium we could see three types of waits such as Implicit Waits, Explicit Waits and Fluent Waits.
·        Implicit Waits 
·        Explicit Waits
·        Fluent Waits  

37. What is Implicit Wait in Selenium WebDriver?
Implicit waits tell to the WebDriver to wait for a certain amount of time before it throws an exception. Once we set the time, WebDriver will wait for the element based on the time we set before it throws an exception. The default setting is 0 (zero). We need to set some wait time to make WebDriver to wait for the required time.
38. What is WebDriverWait /Explicit Wait in Selenium WebDriver?
WebDriverwait is applied on a certain element with defined expected condition and time. This wait is only applied to the specified element. This wait can also throw an exception when an element is not found.
39. What is Fluent Wait in Selenium WebDriver?
FluentWait can define the maximum amount of time to wait for a specific condition and frequency with which to check the condition before throwing an “ElementNotVisibleException” exception.
40. How to input text in the text box using Selenium WebDriver?
By using sendKeys() method
WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath")).sendKeys("Hello");


41. How to input text in the text box without calling the sendKeys()?






// To initialize JavaScript object
JavascriptExecutor JS = (JavascriptExecutor)webdriver;
// To enter username
JS.executeScript("document.getElementById(User').value='User'");
// To enter password
JS.executeScript("document.getElementById('Pass').value='tester'");

42. How to clear the text in the text box using Selenium WebDriver?

WebDriver driver = new FirefoxDriver();
driver.get("https://www.gmail.com");
driver.findElement(By.xpath("xpath ")).sendKeys("Username");
driver.findElement(By.xpath("xpath ")).clear();



43. How to get a text of a web element?
By using getText() method
String Value = driver.findElement(By.xpath("xpath_")).getText();
44. How to get an attribute value using Selenium WebDriver?
By using getAttribute(value);
It returns the value of the attribute passed as a parameter.
HTML Code Below-
<input name="Purush" value="India">Hello</input>
 Selenium Code -
 String Value =   driver.findElement(By.name("Purush")).getAttribute("value");
 Output: India



45. How to click on a hyperlink using Selenium WebDriver?

We use click() method in Selenium to click on the hyperlink

driver.findElement(By.linkText(“Purush Link”)).click();










1 comment: