1. What is Automation Testing?
Automation Testing is Software Testing Technique where the actual and expected outcome is validated using Programmatically using Automation Tools.
2. What is Selenium Webdriver?
Selenium Webdriver is an Open source tool that contains a collection of APIs which is used to verify the result of test cases programmatically.
Or.
Selenium Webdriver is an Open Source Automation Tool, which contains a collection of API’s which is used to test the web application using supported programming languages.
3. I have a use case that I need to execute some of the tests only once, I don’t have to execute these tests in the future, Should I use selenium Webdriver for this?
The Standard Practice for Automation Testing is to Automate only repetitive tasks, as creating and setting up Automation Tests involves cost and effort. In the above use case, the test is performed only once so it is not recommended to use automation.
4. Explain Selenium Webdriver Architecture with Selenium 4.
Selenium and Selenium Webdriver are used interchangeably because Selenium Webdriver is the most used one. Selenium webdriver is used for creating browser-based tests like regression, smoke, or functional automation tests.
Earlier Selenium was communicating with the browser using JSON Wire protocol but with the latest Selenium 4 selenium completely moved into W3C Wedbriver Protocol, so Selenium now controls browsers natively.
Selenium Architecture | Image : www.selenium.dev
Components of Selenium webdriver
Webdriver Bindings: Selenium provides a set of commands which can be written using different languages. Since Selenium Supports many languages like Java, C#, Python, etc. each language has a set of selenium commands design, as per programming languages standards. Selenium always ensures that similar commands are available for all the supported languages to perform an interaction with the browser. Using the command one can write the selenium test automation scripts.
Driver: Drivers are browser-specific for example If we want to run our scripts on Chrome Browser, we need to have ChromeDriver in place, likewise for Firefox and Edge. The Driver helps to control the browser behavior.
Browsers: Browsers are the actual browsers like Chrome, Firefox, Edge, Safari, etc, the commands will be executed, and the interactions can be seen visually.
5. What is the advantage of Selenium.
Advantages of Selenium
- Open Source: Selenium is shipped with Apache 2.0 License which means that it is open-source anyone can use. No need to purchase.
- Cross Browser Support: Selenium Supports almost all major browsers Firefox, Chrome, IE, Edge, Firefox, Safari. So, all our use cases related to cross-browser testing can be covered using Selenium.
- Cross-Platform Support: Selenium can be used and run tests across multiple platforms such as Windows, Linux, and Mac-based machines.
- Well Written Documentation: Selenium has documented everything, which is easy for anyone to refer to and implement the same. Selenium has recently updated documentation where we can search for any commands APIs provided by selenium it describes the same.
- Community Support: Since Selenium is used by thousands of uses, community support is good, most of the questions are already answered on various forums. Apart from that, there are tons of tutorial which makes our job easier.
- Language Support: Selenium Support many languages JavaScript (Node.js), Python, Ruby, Java, and C#, etc. Bindings are updated more often to ensure all the features are available across the selenium-supported languages.
- High Customization: There are many modern web automation frameworks that come as Framework Ready, most of the framework restricts customization, or customization is limited to some extent. The Selenium shipped in pure format, you can customize the way you want. Many organizations created frameworks combining selenium and many other tools.
- Simulate almost everything: Whether it is a keyboard event, mouse event Selenium doesn’t restrict this, almost all the events can be simulated to interact with the browser.
- Support for Chrome DevTools: The latest Selenium 4 has also introduced the feature called Chrome DevTools Support, This is the major feature of Selenium 4 with this feature one can Emulate the Network Bandwidth, Block Urls, Mock API calls, Emulate Devices, Emulate Geo Location many more.
- Screenshot Support: The Selenium Screenshot support is introduced in Selenium 4, Screenshot can be taken at the page level or Web Element Level with just a few lines of code.
- Selector Support: Selenium allows to use of different types of selectors like XPath, CSS, ID, Class, etc. we are not restricted here.
6. What are the different languages supported by Selenium?
Selenium Supports Following Languages
- C#
- Java
- Python
- Ruby
- Javascript
7. Can we use Selenium for Product Development? If not, What is selenium used for?
Selenium is Not a Product Development Framework, Selenium is Automation Testing Framework. Selenium can be used for testing Web Applications.
8. What is Selenium IDE? when should we use it?
The Selenium-IDE (Integrated Development Environment) is the tool, used to develop your Selenium test cases. Selenium IDE is useful for beginners, where they want to write less code and actions can be done using User Interface (UI).
9. How to install Selenium IDE?
Selenium IDE is supported as a browser Plugin or Add On. Installation is simple Just like installing any other Plugins. Selenium IDE is supported officially in Chrome and Firefox. However, Edge also has the Selenium IDE plugin.
For Example, If we need to install Selenium IDE as Plugin to Chrome we need to go to Chrome Webstore and search for Selenium IDE and click on Install to install the Selenium Chrome IDE. Similarly for other browsers.
10. What is Selenese?
Selenium is the Web Automation Tool, which provides a set of Selenium commands to test the web applications. These Selenium Commands are often referred to as Selenese.
11. What are the different types of Locator Strategy supported by Selenium?
Selenium supports almost all types of locators.
- Class name: Locates the elements using Class Name
- CSS Selector: Locates the Element using CSS selectors
- ID: Locates the Element using the ID attribute
- Name: Locates elements whose NAME attribute matches the search value
- Link Text: Locates anchor elements whose visible text matches the search value
- Partial Link Text: Locates anchor elements whose visible text contains the search value. If multiple elements are matching, only the first one will be selected.
- Tag Name: Locates elements whose tag name matches the search value
- Xpath: Locates elements matching an XPath expression
12. Explain List of Supported Drivers by Selenium?
Selenium Communicates with browser using drivers, Each browser has its specific drivers.
- Chrome Driver: Chrome/ Chromium based browsers
- GeckoDriver: Firefox Browsers
- InternetExplorerDriver: Internet Explorer Browser
- Safari Driver: Safari Browser
- Edge Driver: Edge Browser
13. How to find Single and Multiple Elements in Selenium?
Single Element can be found by using the FindElement command
Example:
WebElement academy = driver.findElement(By.id("rahulshettyacademy"));
Multiple Elements can be find using FindElements Command
Example:
List<WebElement> books= driver.findElements(By.cssSelector("#books li"));
14. What is By in selenium?
By is the class in Selenium, it provides the locater specific methods and can be used with driver.findElement(s) to get the Element.
List of Important Methods provided by By Class
Id()
linkText()
partialLinkText()
name()
tagName()
xpath()
className()
cssSelector()
15. Explain at least 5 different types of exceptions in Selenium.
NoSuchElementException
Reason: The exception occurs when WebDriver is unable to find and locate elements. The incorrect locator can cause this exception in selenium.
TimeoutException
Reason: Selenium waits until a specific time period, If the element could not display or load in specified time.
WebDriverException:
Reason: Webdriver performs actions immediately after ‘closing’ the browser or it can also occur when our code unable to initialize the webdriver
ElementNotVisibleException
Reason: Selenium tries to perform action on invisible Elements
NoSuchSessionException
Reason: When webdriver cannot execute the commands using driver instance.
NoAlertPresentException
Reason: The user is trying to handle an alert that is not present.
NoSuchWindowException
Reason: WebDriver tries to switch to an invalid window.
16. Explain Explicit Implicit and Fluent waits in Selenium?
17. What is the difference between driver.close and driver.quit?
The driver.close() command closes the current browser window having focus. If there is only one browser open then closes the whole browser session.
The driver.quit() quits the whole browser session along with all the associated browser windows, tabs, and pop-ups.
18. Explain Selenium Browser Naivigation commands.
driver.get() : Used to navigating to webpage
Example:
driver.get("https://rahulshettyacademy.com/");
driver.getCurrentUrl(): Reads the current URL from the browser’s address.
driver.navigate().back(); : Navigates back to previous page. Equivalant to clicking browser back button.
driver.navigate().forward() : Navigates forwards way. Equivalant to clicking browser forward button.
driver.navigate().refresh(); : Refreshs the current page19. How to type text in an input box using Selenium?
Selenium provides sendKeys() method to type the text in the input box or any editable content. Using sendKeys() command we can type the text.
Example:
WebElement searchBox = driver.findElement(By.name("searchbox"));
searchBox.sendKeys("webdriver");
20. How to click an Element in Selenium?
Selenium provides command .click(), We can use .click() command to click on clickable eelemnts.
Example:
driver.findElement(By.id("ClickMe")).click(); //using Selenium click button method
21. How to Get Text of Web Element?
The getText() method is used for getting the visible, inner text (which is not hidden by CSS) of the web element.
In Some of the cases the getText() may return empty or null content. Using getAttribute('innerText') and getAttribute('value') may return the expected text.
String text = driver.findElement(By.id("someID").getText();
String text = driver.findElement(By.id("someID").getAttribute("innerHTML");
String text = driver.findElement(By.id("someID").getAttribute("value");
22. How to handle window dialog such as File Open Dialog in Windows using Selenium?
Selenium supports only Web Application Automation, Window-based dialog cannot be automated using Selenium. However integrating with tools like Autoit, Robot Class will be helpful in this case.
23. What is Page Object Model?
Page Object Model (POM), is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and maintenance.
In-Page Object Model, Each web page of an application as a class file. Each class file will contain only corresponding web page elements. The class will be imported inside the Class which contains the actual test and actions will be performed.24. Is it possible to use the Assertions only by using Selenium?
Selenium is known for simulations of user actions on the browser, To use the assertions we need to rely on Assertions Framework Such as Junit, TestNG etc.
25. What are the different types of frameworks?
Page Object Model: Page Object Model (POM), is a design pattern in Selenium that creates an object repository for storing all web elements. It is useful in reducing code duplication and maintenance. In-Page Object Model, Each web page of an application as a class file. Each class file will contain only corresponding web page elements
Data-Driven Framework: When the entire test data is generated from some external files like Excel, CSV, XML, or some database table, then it is called Data Driven framework
Keyword Driven Framework: When only the instructions and operations are written in a different file like an Excel worksheet, it is called Keyword Driven framework.
Hybrid Framework: Any combination above frameworks like POM, Data-Driven, Keyword Driven is called a Hybrid Framework.