Selenium Interview Question and Answers
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.
Q: Name the different Selenium components.
A: The Selenium Suite comprises Selenium IDE, Selenium RC, Selenium WebDriver, and Selenium Grid.
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.
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.
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.
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.
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.
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.
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.
Q: What is WebDriver's close command?
A: The close command closes the current browser window on which the focus is set.
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.
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.
Q: How can you insert a pause in your tests?
A: You can insert a pause in your tests using the Thread.sleep command.
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.
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.
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.
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().
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.
Q: How do you switch between frames in Selenium?
A: You can switch between frames using the switchTo().frame() method in Selenium.
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.
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.
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.
Q: How to perform right click using WebDriver?
A: Right click can be performed using Actions class and contextClick() method in WebDriver.
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.
Q: What is the use of JavaScript Executor?
A: JavaScript Executor is used to execute JavaScript code in Selenium.
Q: What is Robot class in Selenium?
A: Robot class is used to simulate keyboard and mouse events in Selenium.
Q: How to handle multiple windows in Selenium?
A: Multiple windows can be handled in Selenium using getWindowHandles and switchTo().window() methods.
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.
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.
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.
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.
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.
Q: What is Selenese?
A: Selenese is the language used to write test scripts in Selenium IDE.
Q: How to handle frames in Selenium WebDriver?
A: Frames in Selenium WebDriver can be handled using switchTo().frame() method.
Q: What is the use of AutoIT tool?
A: AutoIt is a tool used to handle windows based pop-ups in Selenium.
Q: How do you take screenshots in Selenium?
A: Screenshots can be taken using the TakeScreenshot interface and its method getScreenshotAs(OutputType).
Q: How do you scroll web page in Selenium?
A: Scrolling can be achieved in Selenium using JavaScriptExecutor and the scrollTo method.
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.
Q: How do you handle cookies in Selenium?
A: Selenium provides methods to handle cookies, such as addCookie, getCookies, deleteCookie.
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.
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.
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).
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.
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.
Q: What is GeckoDriver in Selenium?
A: GeckoDriver is a link between Selenium tests and Mozilla Firefox browser.
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.
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().
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.
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.
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.
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.
Q: What is chromedriver in Selenium?
A: ChromeDriver is a standalone server or a separate executable that WebDriver uses to control Chrome.
Q: What is the use of DeSelect in Selenium WebDriver?
A: DeSelect is used to unselect options in a dropdown in Selenium WebDriver.
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.
Q: How to handle a dropdown in Selenium WebDriver?
A: Dropdowns can be handled in Selenium using the Select class and its methods.
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.
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.
Q: How to retrieve CSS properties of an element?
A: CSS properties can be retrieved using the getCssValue() method in Selenium.
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.
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