Top Selenium Interview Questions & Answers

Selenium Interview Questions & Answers
Table of Contents

1. What is Selenium?

Selenium is an open-source, automated testing tool that is used to test web applications across various browsers. It can test only web applications and not mobile and desktop applications.

2. What are the different Selenium suites Components?

Selenium is not just a single tool or utility, but rather a package of several testing tools and that’s why it’s called Selenium Suite.

  • Selenium IDE (Integrated Development Environment): It is a tool for recording and playing back.
  • WebDriver and RC: It provides the APIs for a variety of languages like Java, .NET, PHP, etc. With most of the browsers Webdriver and RC work.
  • Grid: With the help of Grid you can distribute tests on multiple machines so that tests can be run parallel which helps cut down the time required for running in-browser test suites

3. What do you mean by Selenese?

Selenese which is called the Selenium command is the set of the Selenium commands that run your test cases. For example, open (URL) is a Selenium command that opens the specified URL in the specific browser. A test script is the sequence of all these commands put together.

4. What are the types of Selenese?

  • Actions: We can use it to perform interactions and operations on the target elements
  • Accessors: These are used for storing the values in the variables.
  • Assertions: These can be used as checkpoints to keep track of the sequential flow of commands.

5. What is the use of Selenese and what can be tested using Selenese?

Selenese commands are used to test the web applications. The tester can test the broken links, the existence of some objects on the UI, Ajax functionality, alerts, windows, list options, and a lot more using Selenese.

6. Which browsers/drivers are supported by Selenium Webdriver?

Selenium WebDriver supports several popular web browsers, including Google Chrome, Mozilla Firefox, Microsoft Edge, Safari, and Opera.

7. What are the limitations of Selenium testing?

  • No support for desktop applications
  • Requires expertise
  • No Image Testing
  • No Reporting capability
  • High Maintenance and Scalability
  • No support for REST and SOAP Platforms

8. What makes Selenium such a widely used testing tool? Give reasons.

  • Selenium is an open-source automation tool
  • Selenium can test web applications against browsers like Firefox, Opera, Chrome, and Safari
  • Selenium is platform-independent and can be deployed on different Operating systems like Windows, Linux, and Macintosh.
  • The test code can be written in various programming languages like Java, Perl, Python, and PHP.
  • Selenium can be integrated with third-party tools like JUnit and TestNG for test management

9. What is the use of the driver.get() command in Selenium WebDriver?

This command will instruct the Selenium WebDriver to open the specified URL in the web browser.

10. What is an alternative option to driver.get() method to open a URL in Selenium Web Driver?

An alternative option to the driver.get() method to open a URL in Selenium Web Driver is to use the driver.navigate().to() method.

Selenium interview questions and answers

11. What are Locators in Selenium?

Locators in Selenium are methods used to identify and locate web elements on a web page. They are essential to automation testing as they help automate discovery and interaction with web elements.

12. What are the various ways of locating an element in Selenium?

  • id
  • xpath
  • cssSelector
  • className
  • tagName
  • name
  • linkText
  • partialLinkText

13. What is an XPath?

Xpath or XML path is a query language that is used for selecting nodes from XML documents. Also, it is one of the locators supported by Selenium Webdriver.

14. What is the difference between the Absolute path and the Relative Path? What is the use of X-path?

Absolute Path

  • This path starts from the root node and ends with the desired elements node.
  • It starts with a single slash (/)
  • Example: /html.body/div/td/input

Relative Path

  • This path starts from any node in between and to the desired elements node.
  • It starts with a double slash (//)
  • Example: //input/example[@id=name]

X-Path is used to find the WebElement in web pages. It is also useful in identifying the dynamic elements.

15. What is the use of an ID locator?

When the ID attribute is given to an element that is unique on a webpage. It is the fastest and most reliable way to locate an element.

16. What is the use of name locator?

When the name attribute is given to an element. It may not be unique, but it is commonly used to identify elements.

17. What is the use of class name locator?

Multiple elements can have the same class attribute, but it is still a reliable way to locate elements. It is used mostly in radio buttons, checkboxes, or dropdowns in case no other attribute is given.

18. What is the use of tag name locator?

It is useful when only one element has a particular tag name.

19. What is the use of a link text locator?

It is used to find an anchor element (“a” tag) with a specific link text and identify links on a webpage.

20. What is the use of a partial link text locator?

It is used to find an anchor element (“a” tag) with a partial link text and identify links with a familiar pattern on a webpage.

Selenium interview questions and answers

21. What is the difference between findElement() and findElements()?

findElement():

It uses the given locating mechanism to find the first element within the current page and return a single web element.

findElements():

It also uses the given locating mechanism to find all the elements within the current page and return the list of all web elements.

22. What is the major difference between driver.close() and driver.quit()?

driver.close():

It’s a command by which the current window can be closed. For example, if we have multiple browser windows open then, by using this command we can close the window with which the focus is.

driver.quit():

This command closes all the open browser windows. For example, if we have multiple browser windows open then, this command can close all the windows at once.

23. What is the difference between isSelected(), isEnabled(), and isDisplayed()?

isSelected() is the method used to verify if the web element is selected or not.

isEnabled() is the method used to verify if the web element is enabled or disabled within the webpage. isEnabled() is primarily used with buttons.

isDisplayed() is capable of checking for the presence of all kinds of web elements available.

24. How do you launch the Firefox browser using WebDriver?

WebDriver driver = new FirefoxDriver();

25. What is the difference between getText() and getAttribute() in Selenium?

getText() returns the visible text of a web element, while getAttribute() returns the value of a specific attribute of the web element.

26. How to type text in an input box using Selenium?

sendKeys() is the method used to type text in input boxes

27. How to click on a hyperlink in Selenium?

driver.findElement(By.linkText(“Click here”)).click();

28. How to verify the title of a webpage?

//Get the title of the webpage and store it in a variable. 
String actualTitle = driver.getTitle();
//Type in the expected title
String expectedTitle = “ABC";
//Verify if both of them are equal
   if(actualTitle.equalsIgnoreCase(expectedTitle)) {
   System.out.println("Title Matched");
}
  else{
  System.out.println("Title didn't match");
}

29. Can Captcha be automated?

No, Selenium cannot automate Captcha. The automation test engineer has to manually type the captcha while other fields can be filled automatically.

30. What do you mean by WebElement?

The WebElement is an interface in Selenium that is used to represent an HTML element on a web page. It provides methods to interact with the web elements, such as clicking, entering text, and getting the value. It is used to identify and manipulate the web elements in the automation testing process.

Selenium interview questions and answers

31. How to switch between windows?

switchTo() command is used to switch between windows. Every window instantiated by the WebDriver is given a unique alphanumeric value called “Window Handle”.

32. How to maximize the browser window in Selenium?

To maximize the window

driver.manage().window().maximize();

33. What is the difference between the getwindowhandle() and getwindowhandles()?

  • getwindowhandles(): This is used to get the address of all the open browsers and returns the data type of Set<String>.
  • getwindowhandle(): This is used to get the address of the current browser window where it’s focused and returns the data type of String.

34. Explain Implicit wait, Explicit wait, and Fluent wait.

Implicit wait:

We can set the timeout for a specific amount of time for all the successive web elements. In this specified time, the web driver searches for all the web elements before throwing the NoSuchElementException.

driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(2));

Explicit wait:

We can tell the Web Driver to wait for certain conditions before throwing the ElemntNotVisibleException.

Wait<WebDriver> wait = new WebDriverWait(driver, Duration.ofSeconds(2));

Fluent wait:

It’s a slight extension of the explicit wait. Apart from waiting for certain conditions to be met, we can also set the frequency with which we check the condition before throwing the ElementNotVisibleException.

Wait wait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(TIMEOUT))
.pollingEvery(Duration.ofMillis(POLL_FREQUENCY));

35. What are the Testing types that are supported by Selenium?

Testing Types supported by Selenium - Selenium Interview Questions & Answers

36. What is the difference between a single slash(/) and a double slash(//) in XPath?

In XPath, a single slash is used for creating absolute XPaths, beginning from the root node. Whereas double slash is used for creating relative XPaths.

37. How to switch between multiple windows in Selenium?

Selenium has driver.getWindowHandles() and

driver.switchTo().window(“{windowHandleName}”)

commands to work with multiple windows.

The getWindowHandles() command returns a list of IDs corresponding to each window. If we pass a particular window handle to the

driver.switchTo().window(“{windowHandleName}”)

command then we can switch control/focus to that particular window.

for (String windowHandle : driver.getWindowHandles()) {
     driver.switchTo().window(handle);
}

38. What are the different ways to refresh a browser?

There a multiple ways to refresh a page in Selenium-

  • Using driver.navigate().refresh() command.
  • Using sendKeys(Keys.F5) on any textbox on the webpage.
  • By using a driver.get(“URL”) on the current URL or using driver.getCurrentUrl().
  • Using driver.navigate().to(“URL”) on the current URL or driver.navigate().to(driver.getCurrentUrl());

39. How can we fetch a text written over an element?

Using the getText() method we can fetch the text over an element.

String text = driver.findElement("elementLocator").getText();

40. How can we find the value of different attributes like name, class, and value of an element?

Using getAttribute(“{attributeName}”) method, we can find the value of different attributes of an element e.g.-

String valueAttribute =
driver.findElement(By.id("locator")).getAttribute("value");
Selenium interview questions and answers

41. How can we find all the links on a web page?

All the links are of anchor tag ‘a’. So by locating elements of tagName ‘a’ we can find all the links on a webpage.

List<WebElement> links = driver.findElements(By.tagName("a"));

42. Mention 5 different exceptions you had in the Selenium web driver

The 5 different exceptions you had in Selenium web drivers are

  • NoSuchElementException – When no element can be located by the locator provided.
  • NoAlertPresentException – When we try to switch to an alert box but the targetted alert is not present.
  • TimeoutException – When a command execution gets a timeout.
  • WebDriverException – When there is some issue with the driver instance preventing it from getting launched.
  • NoSuchWindowException – When we try to switch to a window but the targetted window is not present.

43. How can we capture screenshots using Selenium?

To take screenshots in Selenium, we can use the getScreenshotAs method of the TakesScreenshot interface.

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("D:\\testScreenShot.jpg"));

44. How to handle dropdowns in Selenium?

Using Select class-

Select countriesDropDown = new Select(driver.findElement(By.id("countries")));

There are 3 methods

dropdown.selectByVisibleText("India");
//or using the index of the option starting from 0
dropdown.selectByIndex(1);
//or using its value attribute
dropdown.selectByValue("Ind");

45. How to check which option in the dropdown is selected?

Using is Selected() method, we can check the state of a dropdown’s option.

Select countriesDropDown = new 
Select(driver.findElement(By.id("countries")));
dropdown.selectByVisibleText("India");
//returns true or false value 
System.out.println(driver.findElement(By.id("India")).isSelected());

46. How to do drag and drop in Selenium?

Using the Action class, drag and drop can be performed in Selenium. Example-

Actions builder = new Actions(driver);
Action dragAndDrop = builder.clickAndHold(SourceElement)
.moveToElement(TargetElement)
.release(TargetElement)
.build();
dragAndDrop.perform();

47. How to handle alerts in Selenium?

To accept or dismiss an alert box, the alert class is used. This requires first switching to the alert box and then using accept() or dismiss() command as the case may be.

Alert alert = driver.switchTo().alert(); 
//To accept the alert
alert.accept();
Alert alert = driver.switchTo().alert(); 
//To cancel the alert box
alert.dismiss();

48. What is a Selenium Maven project?

A Selenium Maven project is a software project that uses Maven to manage the project's dependencies and build process.

49. What are the different types of navigation commands?

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.

driver.navigate().back();

navigate().forward() – This command lets the user navigate to the next web page with reference to the browser’s history.

driver.navigate().forward();

navigate().refresh() – This command lets the user refresh the current web page by reloading all the web elements.

driver.navigate().refresh();

navigate().to() – This command lets the user launch a new web browser window and navigate to the specified URL.

driver.navigate().to(“https://google.com”);

50. How to mouse hover over a web element?

Actions class is used to hover over a web element in Selenium WebDriver Instantiate the Actions class object and use the moveToElement() method to hover over the element.

Actions act = new Actions(driver);
act.moveToElement(driver.findElement(By.id("id of the element"))).build().perform();
not found

Master Selenium with Hands-on Exercises!

Explore real-world scenarios; learn element locators and many more to elevate your automation skills.

Proleed Academy

Proleed serves / offers professionally designed IT training courses
globally.

Copyright © 2023 - Proleed Academy | All Rights Reserved.