Selenium Interview Questions and AnswersCegonsoft
Frequently asked Interview Questions with Answer in Selenium
1. What are the annotations used in TestNG ?
A. @Test, @BeforeSuite, @AfterSuite, @BeforeTest, @AfterTest, @BeforeClass, @AfterClass, @BeforeMethod, @AfterMethod.
2. What are the limitations of Selenium?
A. Following are the limitations of Selenium:
- Selenium supports testing of only web based applications
- Mobile applications cannot be tested using Selenium
- Captcha and Bar code readers cannot be tested using Selenium
- Reports can only be generated using third party tools like TestNG or Junit.
- As Selenium is a free tool, thus there is no ready vendor support though the user can find numerous helping communities.
- User is expected to possess prior programming language knowledge.
3. What is Selenium? What are the different Selenium components?
A. Selenium is one of the most popular automated testing suites. Selenium is designed in a way to support and encourage automation testing of functional aspects of web based applications and a wide range of browsers and platforms. Due to its existence in the open source community, it has become one of the most accepted tools amongst the testing professionals.
Selenium is not just a single tool or a utility, rather a package of several testing tools and for the same reason it is referred to as a Suite. Each of these tools is designed to cater different testing and test environment requirements.
The suite package constitutes of the following sets of tools:
- Selenium Integrated Development Environment SIDE– Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
- Selenium Remote Control (RC) – Selenium RC is a server that allows user to create test scripts in a desired programming language. It also allows executing test scripts within the large spectrum of browsers.
- Selenium WebDriver – WebDriver is a different tool altogether that has various advantages over Selenium RC. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
- Selenium Grid – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently
4. What is Selenese?
A. Selenese is the language which is used to write test scripts in Selenium IDE.
5. What is the use of xpath ?
A. It is used to find the WebElement in web page. It is very useful to identify the dynamic web elements.
6. What is the difference between Assert and Verify?
A. Assert- it is used to verify the result. If the test case fail then it will stop the execution of the test case there itself and move the control to other test case.
Verify- it is also used to verify the result. If the test case fail then it will not stop the execution of that test case.
7. How do you handle alert pop-up ?
A. To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or cancle then move control back to main page.
String mainPage = driver.getWindowHandle();
Alert alt = driver.switchTo().alert(); // to move control to alert popup
alt.accept(); // to click on ok.
alt.dismiss(); // to click on cancel.
//Then move the control back to main web page-
driver.switchTo().window(mainPage); → to switch back to main page.
8. What is the difference between “/” and “//” in Xpath?
A. 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.
9. What do we mean by Selenium 1 and Selenium 2?
A. Selenium RC and WebDriver, in a combination are popularly known as Selenium 2. Selenium RC alone is also referred as Selenium 1.
10. How do I launch the browser using WebDriver?
A. The following syntax can be used to launch Browser:
WebDriver driver = new FirefoxDriver();
WebDriver driver = new ChromeDriver();
WebDriver driver = new InternetExplorerDriver();
11. What are the different types of waits available in WebDriver?
A. There are two types of waits available in WebDriver:
- Implicit Wait
- Explicit Wait
Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.
Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.
12. What are the different types of navigation commands?
A. Following are the navigation commands:
navigate().back() – The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history.
navigate().forward() – This command lets the user to navigate to the next web page with reference to the browser’s history.
navigate().refresh() – This command lets the user to refresh the current web page there by reloading all the web elements.
13. When do we use findElement() and findElements()?
A. findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched.
WebElement element = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.
List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));
14. How do I submit a form using Selenium?
A. driver.findElement(By.id(“ElementID”)). submit();
15. What is the difference between driver.close() and driver.quit() command?
A. close(): WebDriver’s close() method closes the web browser window that the user is currently working on or we can also say the window that is being currently accessed by the WebDriver. The command neither requires any parameter nor does is return any value.
quit(): Unlike close() method, quit() method closes down all the windows that the program has opened. Same as close() method, the command neither requires any parameter nor does is return any value.
16. What is a framework?
A. Framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.
17. What are the different types of frameworks?
A. Below are the different types of frameworks:
- Module Based Testing Framework: The framework divides the entire “Application Under Test” into number of logical and isolated modules. For each module, we create a separate and independent test script. Thus, when these test scripts taken together builds a larger test script representing more than one module.
- Library Architecture Testing Framework: The basic fundamental behind the framework is to determine the common steps and group them into functions under a library and call those functions in the test scripts whenever required.
- Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate the test script logic and the test data from each other. It lets the user store the test data into an external database. The data is conventionally stored in “Key-Value” pairs. Thus, the key can be used to access and populate the data within the test scripts.
- Keyword Driven Testing Framework: The Keyword driven testing framework is an extension to Data driven Testing Framework in a sense that it not only segregates the test data from the scripts, it also keeps the certain set of code belonging to the test script into an external data file.
- Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.
- Behavior Driven Development Framework: Behavior Driven Development framework allows automation of functional validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc
18. Give the example for method overload in WebDriver.
A. frame(string), frame(int), frame(WebElement).
19. How do you upload a file?
A. To upload a file we can use sendKeys() method.
driver.findElement(By.xpath(“input field”)).sendKeys(“path of the file”);
20. How do you click on a menu item in a drop down menu?
A. If that menu has been created by using select tag then we can use the methods selectByValue() or selectByIndex() or selectByVisibleText(). These are the methods of the Select class.
If the menu has not been created by using the select tag then we can simply find the xpath of that element and click on that to select.
21. What are the different exceptions you got when working with WebDriver ?
A. ElementNotVisibleException, ElementNotSelectableException, NoAlertPresentException, NoSuchAttributeException, NoSuchWindowException, TimeoutException, WebDriverException etc.
22. What are the languages supported by WebDriver ?
A. Python, Ruby, C# and Java are all supported directly by the development team. There are also webdriver implementations for PHP and Perl.
23. What are the prerequisites to run selenium webdriver?
A. JDK, Eclipse, WebDriver(selenium standalone jar file), browser, application to be tested.
24. What is Selenium Grid ?
A. Selenium-Grid allows you to run your tests on different machines against different browsers in parallel. That is, running multiple tests at the same time against different machines, different browsers and operating systems. Essentially, Selenium-Grid support distributed test execution. It allows for running your tests in a distributed test execution environment.
25. How to check if a button is enabled on the page ?
A. Use isEnabled() method. The return type of the method is boolean. So if it return true then button is enabled else not enabled.
driver.findElement(By.xpath(“xpath of button”)).isEnabled();
26. How to check the checkbox or radio button is selected ?
A. Use isSelected() method to identify. The return type of the method is boolean. So if it return true then button is selected else not enabled.
driver.findElement(By.xpath(“xpath of button”)).isSelected();
27. How can we get a text of a web element?
A. Get command is used to retrieve the inner text of the specified web element. The command doesn’t require any parameter but returns a string value. It is also one of the extensively used commands for verification of messages, labels, errors etc displayed on the web pages.
String Text = driver.findElement(By.id(“Text”)).getText();
28. How do u get the attribute of the web element ?
A. driver.getElement(By.tagName(“img”)).getAttribute(“src”) will give you the src attribute of this tag.
29. How to hover the mouse on an element ?
A. act.moveToElement(webelement); //webelement on which you want to move cursor