Selenium Interview Questions and Answers
![Selenium Interview Questions and Answers Selenium Interview Questions and Answers](https://www.h2kinfosys.com/blog/wp-content/uploads/2020/08/Selenium-Interview-Questions-and-Answers.jpg)
In this article, check out the top 29 Selenium interview questions and Answers to Improve your knowledge on most trending interview questions, of late.
- What is the Main feature that available in QTP but not in Selenium?
Ans: Run from Step is the feature available only in QTP. For Example: In QTP if you have 10 lines of code and if you have to execute the code from line no 5 we can do that in QTP i.e the code will execute on the existing browser which is opened. In QTP we can work on existing browser which is opened at the background but in Selenium it is not possible whenever you run the code we have to run the code from line no 1 and a new browser opens up.
- Tell me about the brief introduction of Selenium?
Ans: Selenium IDE: It is a tool which gets added on to a Mozilla browser as an Addon. It generates no reports. It is a very simple tool which cannot be used on complex projects.
Selenium WebDriver: It is a tool available in multiple languages. It can work on multiple browsers. It can generate reports. It can automate our applications end to end.
Selenium Grid: It is a tool use to run our tests parallel across multiple systems.
- Can Selenium support mobile applications?
Ans: No, Selenium cannot support mobile applications, but there are some frameworks based on Selenium especially used for mobile automated testing i.e Appium and Selendroid.
- Can Client server applications can be automate through the Selenium?
Ans: No, Selenium cannot automate client server applications(desktop), it can automate only web-based applications.
- Which type of testing can be done using Selenium?
Ans: Selenium can be used to perform repetitive functional and regression testing.
- What are the limitations of Selenium IDE or Selenium WebDriver?
Ans: Selenium IDE: It only works on Mozilla. It will not generate reports. It is a tool used to test simple applications.
Selenium WebDriver: It always works on a fresh browser. It cannot work on a browser which is already opened. It is little bit tough to automate Ext JS applications.
- What are the advantages and disadvantages of Selenium?
Ans: Advantages
- It is a free tool
- It operates on multiple operating systems
- It supports multiple browsers
- It supports multiple languages
- It supports distributed test execution
- It can execute the same script in parallel.
- It can handle JavaScript Errors in the application.
- It can simulate the actions performed by human.
- Browser can be minimized while executing the code and can do our other works.
Disadvantages:
- It is little bit tough to automate Ext JS applications.
- It automates only web-based applications
- Image comparison is not possible
- Captcha and Bar Code readers cannot be automated
- Tester should have programming knowledge to automate the applications.
- Recovery scenario is not available by in-built
- What is WebDriver in Selenium?
Ans: It is a web automation framework which allows us to execute test across multiple browsers. It can execute multiple tests over multiple browsers on various Operating Systems.
- When we will go for XPath?
Ans: When elements are not found by general locators like id, class, name, etc. Then we go with XPath to find an element on the web page.
- What types of testing does selenium support?
Ans: Selenium supports Functional Testing and Regression Testing, Acceptance Testing, Retesting, Sanity Testing, Smoke Testing, Cross-browser Testing, UI Testing.
11. What are the different locators available in Selenium?
There are 8 different types of locators in Selenium WebDriver
- ID
- Name
- TagName
- ClassName
- LinkText
- PartialLinkText
- XPath
- CSS Selector
- What are the different types of waits in Selenium WebDriver?
There are three types of waits in Selenium such as Implicit Wait Explicit Wait, and Fluent Wait.
- What is Implicit Wait in Selenium WebDriver?
Implicit Wait(): Implicit wait instructs the Selenium to wait for a certain amount of time before throwing “No such element” exception. Once the time is set, WebDriver will wait for the element based on the given time before it throws an exception. The default setting time is 0 (zero).
- What is Explicit Wait in Selenium WebDriver?
Explicit wait – Explicit wait instructs the Web Driver to wait for certain conditions occur before moving forward with executing the code. Setting Explicit Wait is important in cases where there are certain elements that usually take more time to load. It can only be applied for specified elements. It can be achieved with the combination of WebDriverWait and ExpectedConditions.
- What is Fluent Wait in Selenium WebDriver?
Fluent Wait instructs the webdriver to wait for a specific condition and frequency with which we want to check the condition before throwing an “ElementNotVisibleException” exception. Fluent wait is just a plain class and using this class we can wait until specific conditions are met. It is an implementation of Wait interface. Each fluent wait instance defines the maximum amount of time to wait for a condition and we can give the frequency to check the condition.
- Mention the different types of navigation commands
driver.navigate().to(“www.facebook.com”); – This method will navigates to the given URL
driver.navigate().refresh(); – This method refreshes the current page
driver.navigate().forward(); – This method will click on the Forward Button of any browser. It neither accepts nor returns anything.
driver.navigate().back(); – This method will click on the Back Button of any browser. It neither accepts nor returns anything.
- What is the difference between driver.close() and driver.quit()?
driver.close()
This command closes the current browser’s window. If multiple windows are opened, the window which is currently focued will be closed.
driver.quit()
This command calls the driver.dispose method, which closes all the open browser windows and terminates the WebDriver session.
- What are the types of WebDriver APIs available in Selenium WebDriver?
- Gecko Driver
- Chrome Driver
- InternetExplorer Driver
- HTMLUnit Driver
- Opera Driver
- Safari Driver
- Android Driver
- iPhone Driver
- EventFiringWebDriver
- Which WebDriver API implementation claims to be the fastest and why?
HTMLUnitDriver is the most light weight and fastest implementation of WebDriver. It is based on HtmlUnit. It is known as Headless Browser Driver. It acts same like Chrome, Firefox driver, but it does not have GUI so one cannot see the execution of test on screen.
- What are the different Programming Languages supported by Selenium WebDiver?
- Java
- C#
- Python
- Ruby
- Perl
- PHP
- What are the Operating Systems supported by Selenium WebDriver?
- Windows
- Linux
- Mac OS X
- iOS
- Android
- When you use the locators ID, Name, XPath, Or CSS Selector?
- ID & Name locators are used when there are unique ids & unique names available on the web page.
- CSS Selector is used when ID & Name locators are not unique.
- XPath is used when ID and Name locators not available.
- What is the difference between Single Slash (“/”) and Double Slash (“//”)
Single Slash “/” – The XPath expression which you have created for locating the element starts with ‘/’ is known as Absolute XPath. In XPath expression single slash ‘/’ will search for the immediate child node while locating the web elements on the page.
Double Slash “//” – The XPath expression which you have created for locating the element starts with ‘//’ is known as Relative XPath. In an XPath expression ‘//’ searches for the immediate and next level child node while locating the web elements on the page.
- What is the difference between Absolute Path and Relative Path?
Absolute XPath will starts from the root node and ends with desired descendant element’s node. It starts with top HTML node and ends with the input node. It starts with a single forward slash(/).
Relative XPath will starts from any node of your choice in the HTML page to the current element’s node. It starts with a double forward slash(//).
- How to launch a browser using Selenium WebDriver?
System.setProperty("webdriver.gecko.driver","F:\\drivers\\geckodriver.exe");
driver = new FirefoxDriver();
- Is the FirefoxDriver a Class or an Interface?
FirefoxDriver is a Java class, which implements the WebDriver interface.
- What is the super interface of WebDriver?
SearchContext is the the super interface of Web Driver.
- What is the purpose of creating a reference variable ‘driver’ of type WebDriver as shown below.
WebDriver driver = new FirefoxDriver(); instead of creating FirefoxDriver driver = new FirefoxDriver();
If we create a reference variable driver of type WebDriver then we can use the same driver variable to work with any browser of our choice such as ChromeDriver, IEDriver, SafariDriver etc.
- What are the different exceptions in Selenium WebDriver?
Ans:
- NoSuchElementException: This exception occurs when an element with given attributes is not found on the web page. This is the most and frequent exception we face every time. You will definitely face this kind of exception while automating the applications.
- TimeoutException: This exception is thrown when a command performing an operation does not complete in the given time
- StaleElementException: This exception is thrown when the element has been deleted entirely or when the element is no longer attached to the DOM. This exception is often see when you work with AJAX or heavy JavaScript websites, where continually the DOM is being changed.
- ElementNotVisibleException: This exception is thrown when the element you are trying to locate is present in DOM (Document Object Model), but not visible on the web page to the user. This is also most and very frequent exception we face every time.
- NoSuchFrameException: This is also most and frequent exception we face every time. In modern applications iFrames are very frequently used by people. The code will throw an NoSuchFrameException when you try to find an iFrame on application and it is not exist in the application.
- NoSuchWindowException: This exception is very similar to NoSuchFrameException. A window is a browser which is opened by the WebDriver or child window i.e another browser opened from the parent browser. The code will throw NoSuchWindowException when you try to find a window and that is not available at present.
- InvalidElementStateException: You cannot find this exception frequently. An InvalidElementStateException occurs when the WebElement that you are trying to interact with is not in a state that would allow you to perform the action that you would like to perform.
- SessionNotFoundException: You cannot find this exception frequently. You will get this exception while executing your tests and something will go wrong and will lose connection with the browser instance that you are driving.
- UnreachableBrowserException: We get this exception when you will not get the response from the browser when selenium sends commands to the browser to execute to get the response back.
- What is Selenese?
Selenese is the set of Selenium Commands which is used to write test scripts in Selenium IDE and used to test your web application.
2 Comments