Selenium Interview Question and Answers

a man and woman sitting at a table with a man in a suit and tie
a man and woman sitting at a table with a man in a suit and tie
  1. Q: What is Selenium?

    A: Selenium is a popular open-source web-based automation tool that allows us to automate web applications. It supports multiple browsers and programming languages.

  2. Q: Name the different Selenium components.

    A: The Selenium Suite comprises Selenium IDE, Selenium RC, Selenium WebDriver, and Selenium Grid.

  3. Q: What is Selenium WebDriver?

    A: Selenium WebDriver is a web automation framework that allows you to execute your tests against different browsers. It provides a simple API to write functional/acceptance tests using Selenium WebDriver.

  4. Q: What are the different types of locators in Selenium?

    A: The locators in Selenium include ID, Name, Class Name, Tag Name, Link Text, Partial Link Text, CSS Selector, and XPath.

  5. Q: What is XPath?

    A: XPath, or XML Path Language, is a language for selecting nodes from an XML document which is also used in Selenium as a locator to find elements.

  6. Q: What is the difference between findElement and findElements?

    A: findElement returns the first matching element on the webpage while findElements returns a list of all matching elements on the webpage.

  7. Q: What are the different types of waits available in WebDriver?

    A: There are two types of waits available in WebDriver: Implicit Wait and Explicit Wait.

  8. Q: What is Implicit Wait in Selenium?

    A: Implicit Wait is used to provide a default waiting time between each consecutive test step across the entire test script.

  9. Q: What is Explicit Wait in Selenium?

    A: Explicit Wait is a code you define to wait for a certain condition to occur before proceeding further in the code.

  10. Q: What is WebDriver's close command?

    A: The close command closes the current browser window on which the focus is set.

  11. Q: What is WebDriver's quit command?

    A: The quit command is used to quit the whole browser, regardless of the number of tabs or windows open.

  12. Q: What is Selenium Grid?

    A: Selenium Grid allows us to run tests on different machines against different browsers in parallel, effectively reducing the time for test execution.

  13. Q: How can you insert a pause in your tests?

    A: You can insert a pause in your tests using the Thread.sleep command.

  14. Q: How can you handle alerts in Selenium?

    A: Alerts in Selenium can be handled using the Alert interface, which has methods like accept, dismiss, and getText.

  15. Q: What is a WebDriver session?

    A: A WebDriver session is started when an instance of WebDriver's browser class is created and ends when you call the quit method.

  16. Q: What is a stale element reference in Selenium?

    A: A stale element reference occurs when an element is no longer attached to the DOM due to changes in the webpage.

  17. Q: What are the different types of navigation commands in Selenium?

    A: The different types of navigation commands in Selenium include navigate().to(), navigate().back(), navigate().forward(), and navigate().refresh().

  18. Q: What is TestNG?

    A: TestNG (Test Next Generation) is a testing framework inspired from JUnit and NUnit, designed to simplify a broad range of testing needs, from unit testing to integration testing.

  19. Q: How do you switch between frames in Selenium?

    A: You can switch between frames using the switchTo().frame() method in Selenium.

  20. Q: What is Page Object Model (POM)?

    A: POM is a design pattern to create an object repository for web UI elements, promoting code reusability and readability.

  21. Q: What is the difference between driver.get() and driver.navigate().to()?

    A: driver.get() waits for the page to load completely before control is returned, while driver.navigate().to() does not wait for the page to load fully.

  22. Q: How do you handle dropdowns in Selenium?

    A: Dropdowns can be handled in Selenium using the Select class and its methods like selectByVisibleText, selectByValue, and selectByIndex.

  23. Q: How to perform right click using WebDriver?

    A: Right click can be performed using Actions class and contextClick() method in WebDriver.

  24. Q: What is a headless browser and name a few?

    A: A headless browser is a web browser without a graphical user interface. Examples include PhantomJS, HTMLUnit, and Puppeteer.

  25. Q: What is the use of JavaScript Executor?

    A: JavaScript Executor is used to execute JavaScript code in Selenium.

  26. Q: What is Robot class in Selenium?

    A: Robot class is used to simulate keyboard and mouse events in Selenium.

  27. Q: How to handle multiple windows in Selenium?

    A: Multiple windows can be handled in Selenium using getWindowHandles and switchTo().window() methods.

  28. Q: What is Desired Capabilities in Selenium?

    A: Desired Capabilities is used to set properties for the WebDriver, such as browser name, platform, and version.

  29. Q: What is the difference between Assert and Verify in Selenium?

    A: Assert stops execution and fails the test if the condition is false, while Verify continues with the next test step regardless of the result.

  30. Q: What is Selenium IDE?

    A: Selenium IDE is an integrated development environment for Selenium scripts, implemented as a Firefox extension that allows for recording, editing, and debugging tests.

  31. Q: What is the difference between isDisplayed() and isEnabled()?

    A: isDisplayed() checks if the element is displayed on the web page, while isEnabled() checks if the element is enabled or not.

  32. Q: What is the difference between isSelected() and isDisplayed()?

    A: isSelected() checks if a checkbox, radio button, or option in a select is selected, while isDisplayed() checks if the element is displayed on the web page.

  33. Q: What is Selenese?

    A: Selenese is the language used to write test scripts in Selenium IDE.

  34. Q: How to handle frames in Selenium WebDriver?

    A: Frames in Selenium WebDriver can be handled using switchTo().frame() method.

  35. Q: What is the use of AutoIT tool?

    A: AutoIt is a tool used to handle windows based pop-ups in Selenium.

  36. Q: How do you take screenshots in Selenium?

    A: Screenshots can be taken using the TakeScreenshot interface and its method getScreenshotAs(OutputType).

  37. Q: How do you scroll web page in Selenium?

    A: Scrolling can be achieved in Selenium using JavaScriptExecutor and the scrollTo method.

  38. Q: What is the role of the WebDriverManager in Selenium?

    A: WebDriverManager helps to manage browser drivers, automatically downloading and setting up the required driver binaries.

  39. Q: How do you handle cookies in Selenium?

    A: Selenium provides methods to handle cookies, such as addCookie, getCookies, deleteCookie.

  40. Q: What is the difference between close() and quit() method in Selenium WebDriver?

    A: close() method closes the current browser window, while quit() closes all windows and ends the WebDriver session.

  41. Q: What is an exception test in Selenium?

    A: Exception test in Selenium is a test case designed to pass if an exception is thrown during its execution.

  42. Q: How to send ENTER/TAB keys in Selenium WebDriver?

    A: ENTER/TAB keys can be sent using sendKeys(Keys.ENTER) or sendKeys(Keys.TAB).

  43. Q: How do you upload a file in Selenium WebDriver?

    A: File upload can be achieved using the sendKeys() method on the file input field to send the path of the file to be uploaded.

  44. Q: How do you manage session storage in Selenium WebDriver?

    A: Selenium WebDriver allows managing session storage using JavaScriptExecutor to execute JavaScript commands for storing, retrieving, and removing items.

  45. Q: What is GeckoDriver in Selenium?

    A: GeckoDriver is a link between Selenium tests and Mozilla Firefox browser.

  46. Q: What is the difference between driver.findElement and driver.findElements in Selenium?

    A: driver.findElement returns the first matching element, while driver.findElements returns a list of all matching elements.

  47. Q: How do you select value in a dropdown?

    A: Values in a dropdown can be selected using the Select class and its methods like selectByVisibleText(), selectByValue(), and selectByIndex().

  48. Q: What is the use of the Page Factory class in Selenium?

    A: Page Factory is used for initializing elements of a Page class without using findElement/s method.

  49. Q: How do you handle SSL certificates in Selenium?

    A: SSL certificates can be handled in Selenium by using Desired Capabilities to accept all certificates or by creating a custom profile.

  50. Q: What is the purpose of the get() function in Selenium?

    A: The get() function is used to navigate to a URL or load a web page in the current browser window.

  51. Q: How do you clear the text in a textbox using Selenium WebDriver?

    A: The text in a textbox can be cleared using the clear() method in Selenium WebDriver.

  52. Q: What is chromedriver in Selenium?

    A: ChromeDriver is a standalone server or a separate executable that WebDriver uses to control Chrome.

  53. Q: What is the use of DeSelect in Selenium WebDriver?

    A: DeSelect is used to unselect options in a dropdown in Selenium WebDriver.

  54. Q: What is the difference between findElement and findElements?

    A: findElement returns the first element found, findElements returns all elements that match the search criteria.

  55. Q: How to handle a dropdown in Selenium WebDriver?

    A: Dropdowns can be handled in Selenium using the Select class and its methods.

  56. Q: How to handle radio buttons in Selenium WebDriver?

    A: Radio buttons can be handled in Selenium by finding them using their locator and using the click method.

  57. Q: How to handle check boxes in Selenium WebDriver?

    A: Check boxes can be handled in Selenium by finding them using their locator and using the click method.

  58. Q: How to retrieve CSS properties of an element?

    A: CSS properties can be retrieved using the getCssValue() method in Selenium.

  59. Q: How to check if an element is visible on the webpage?

    A: Visibility of an element can be checked using the isDisplayed() method in Selenium.

  60. Q: How to check if a button is enabled on the webpage?

    A: The state of a button can be checked using the isEnabled() method in Selenium.

Click here for Selenium Training in Vizag

Related Blogs

Selenium Framework Architecture

QTP v Selenium

What is selenium?