Top Selenium Interview Questions & Answers

5.00 avg. rating (98% score) - 6 votes
Selenium-interview-questions

Selenium is a suite of tools to automate web browsers across many platforms. It is a free, open-sourced application which caters to different testing requirements. This application also supports authoring of tests without having to learn a scripting language and provides a domain-specific language to writes tests in a number of popular programming language. It also runs on most of the modern browsers.

Due to the many advantages Selenium has to offer, it is one of popular testing frameworks and Selenium professionals are in great demand across the IT industry. To prepare for your next interview on Selenium, here are some of the frequently-asked Selenium interview questions (with answers) to help you prepare well.

Q1. How many languages does Selenium support?

Ans. All major languages, including C#, Java, PHP, Ruby, Python.

Q2. What is automation testing?

Ans. Automation testing or Test Automation is a process of automating the manual process to test the application/system under test.

Q3. What are the different ways to find an element?

Ans. ID, Name, Tag, Attribute, CSS, Linktext, PartialLink Text, X-path

Q4. What are the testing types supported by Selenium?

Ans. Functional testing and regression testing

Q5. What is the difference between implicit wait and explicit wait in selenium WebDriver?

Ans. When an implicit wait is implemented in tests, if WebDriver cannot find an element in the Document Object Model (DOM), it will wait for a defined amount of time for the element to appear in the DOM.

An explicit wait can be used where synchronization is needed, for example the page is loaded but we are still waiting for a call to complete and an element to appear.

Q6. Which is better – implicit wait or explicit wait?

Ans. Explicit waits are better than implicit wait. Unlike an implicit wait, you can write custom code or conditions for wait before proceeding further in the code.

Q7. When should I use Selenium IDE?

Ans. Selenium IDE is the simplest of all the tools in the package and should be a great tool for naïve users as it is easy to learn with minimal acquaintances in programming language.

Q8. Explain the difference between single (/) and double slash (//) in X-path?

Ans. Single slash (/) allows the creation of ‘absolute’ path expressions, while double slash (//) allows the creation of ‘relative’ path expressions.

Q9. What is the use of X-path?

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

Q10. What is the difference between type keys and type commands?

Ans. Type key populates the value attribute using JavaScript whereas type commands emulate like actual user typing

Q11. What is the difference between verify and assert commands?

Ans. Assert command allows to check whether an element is on the page or not. Verify command checks whether the element is on the page, otherwise the test will carry on executing.

Q12. What is heightened privileges browsers?

Ans. Heightened privileges browsers are similar to Proxy Injection, allows websites to do something that are not commonly permitted.

Q13. Explain what is Data-driven framework and Keyword driven?

Ans. In Data-driven framework, the test data is separated and kept outside the Test Scripts, while test case logic resides in Test Scripts.

Keyword driven frameworks requires the development of data tables and keywords, independent of the test automation.

Q14. What is Object Repository?

Ans. Object repository is an essential entity in any UI automations which allows a tester to store all object that will be used in the scripts in one or more centralized locations rather than scattered all over the test scripts.

Q15. Mention 5 different exceptions you had in Selenium WebDriver?

Ans. The 5 different exceptions in Selenium WebDriver are WebDriver Exception, NoAlertPresentException, NoSuchWindowException, NoSuchElementException, TimeoutException

Q16. Which web driver implementation is fastest?

Ans. HTMLUnit Driver implementation is fastest

Q17. How to find more than one web element in the list?

Ans. It can be done using WebElement List. E.g.

List <WebElement> elementList = driver.findElements(By.xpath(“//div[@id=’example’]//ul//li”));

int listSize = elementList.size();

for (int i=0; i<listSize; i++)

{

serviceProviderLinks.get(i).click();

driver.navigate().back();

}

Q18. What is the difference between driver.close() and driver.quit() command?

Ans. Close() method closes the web browser window that the user is currently working on or the browser that WebDriver is currently accessing.

Quit() method closes down all the windows that the program has opened.

Q19. In which format does source view shows your script in Selenium IDE?

Ans. XML

Q20. What is Object Repository? How can we create Object Repository in Selenium?

Ans. Object Repository is a term used to refer to the collection of web elements belonging to Application Under Test (AUT) along with their locator values.

In Selenium, objects can be stored in an excel sheet which can be populated inside the script whenever required.

Q21. What is Selenese and what are the types of Selenese ?

Ans. Selenese is a selenium set of command which are used for running the test.

There are three types of Selenese – Actions, Assertions and Accessors

Q22. How you can convert any Selenium IDE tests from Selenese to another language?

Ans. The format option of Selenium IDE to convert tests into another programming language

Q23. To generate pdf reports mention what Java API is required?

Ans. API IText

Q24. What are the ways you can customize TestNG report?’

Ans. You can customize TestNG report in two ways,

  • Using ITestListener Interface
  • Using IReporter Interface

Q25. In Selenium what are Breakpoints and Startpoints?

Ans. A breakpoint is implemented to stop an execution to check if the code is working as expected till now.

A startpoint indicates the point from where the execution should begin.

Q26. What is Selenium composed of?

Ans. Selenium is a suite of tools for automated web testing and it is composed of Selenium IDE (Integrated Development Environment), WebDriver and RC, and Grid.

Q27. Can you tell me from where the term Selenium derived?

Ans. Well, it came from a joke made by Jason Huggins (the developer of Selenium) in an email, where he mocked one of his competitors named Mercury, saying that you can cure mercury poisoning by taking selenium supplements. This is from where the other email recipients took the name and the rest is history.

Also ReadTop QA Interview Questions and Answers

Q28. Why should you use Selenium as a test tool?

Ans. Selenium is a free and open source tool, and has a large user base. It helps communities and is compatible with every browser (Chrome, Firefox, Internet Explorer, etc.). Besides, it also has a great platform compatibility (Windows, Mac OS, Linux etc.)

Q29. What is Selenese?

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

Q30. How many programming languages does Selenium support?

Ans. Selenium supports multiple programming languages like Java, C#, Ruby, Python, Pearl, etc.

Q31. What are the different Selenium components?

Ans. Different components of Selenium are sets of tools, which include:

  • Selenium Integrated Development Environment (IDE)
  • Selenium Remote Control (RC)
  • Selenium WebDriver
  • Selenium Grid

Q32. Elaborate the functioning of Selenium Grid?

Ans. Selenium Grid sends tests to the hub, which are then redirected to Selenium Webdriver. It then launches the browser and runs the test. The tests run in parallel with entire test suite.

Q33. Can we use Selenium grid for performance testing?

Ans. Yes, but it is not as effective as Loadrunner, which is a dedicated Performance Testing tool.

Q34. Which testing types are supported by Selenium?

Ans. Selenium supports two types of testing:

  1. Functional Testing
  2. Regression Testing

Q35. How will you find an element using Selenium?

Ans. Every object or control in a web page is an element in Selenium, and some of the ways to find that element in a web page include using ID, Name, Tag, Attribute, CSS, Linktext, PartialLink Text and Xpath.

Q36. What is Page Object Model (POM)?

Ans. POM is a design pattern responsible for creating an Object Repository for web UI elements.

Q37. What is Page Factory?

Ans. Page Factory provides an optimized way to implement Page Object Model and it has a very good memory utilization and implementation is object-oriented.

Q38. What is an XPath?

Ans. XPath is a language which helps to locate and process items in Extensible Markup Language (XML) documents. It addresses syntax based on a path through the document’s logical structure or hierarchy. XPath is used to locate a web element based on its XML path. It also stores, organizes and transports arbitrary data.

Q39. What is the difference between “/” and “//” in Xpath?

Ans. “/” or Single Slash creates Xpath from the document node/start node.

“//” or Double Slash creates Xpath with relative path from anywhere within the document.

Q40. Which test types are supported by Selenium?

Ans. So, Selenium supports –

  • Functional Testing
  • Regression Testing
  • Sanity Testing
  • Smoke Testing
  • Responsive Testing
  • Cross Browser Testing
  • UI testing (black box)
  • Integration Testing

Q41. What is the difference between type keys and type commands?

Ans. Type Keys trigger JavaScript event but the Type Command don’t. Type key simulates each keystroke using JavaScript, while whereas Type Command emulates actual user typing.

Q42. What is the difference between verify and assert commands?

Ans. Assert command helps to check the availability of a certain element on the page. The test terminates at the point the check fails, i.e. if the element is unavailable.

Verify command also helps to check the availability of a certain element on the page, but here the test goes on as all the commands run is guaranteed even if the check fails.

Q43. Can Selenium handle windows based pop up?

Ans. Since it is an automation testing tool and supports only web application testing, it can’t handle windows pop up. However, third-party tools like AutoITm and Robot class are available to handle this.

Q44. How do we handle web-based pop up in Selenium?

Ans. We can use WebDriver, which provides an efficient way to handle these pop-ups using Alert interface. Besides, there are four methods too that we can use –

void dismiss() – The accept() method clicks on the “Cancel” button when the pop-up window appears.

void accept() – The accept() method clicks on the “Ok” button when the pop-up window appears.

String getText() – The getText() method returns the text displayed on the alert box.

void sendKeys(String stringToSend) – The sendKeys() method enters the specified string pattern into the alert box.

Syntax:

// accepting javascript alert

Alert alert = driver.switchTo().alert();

alert.accept();

Q45. Tell me how can I take a screenshot in Selenium WebDriver?

Ans. You can do that by using the TakeScreenshot function and by using getScreenshotAs() method, you can save the screenshot.

Q46. Is it possible to enter a text without using sendKeys()?

Ans. Yes, we can enter/ send text using JavaScriptExecutor, and we don’t need to use sendKeys() method.

Q47. What is Junit?

Ans. It is a Java-based unit testing framework introduced by Apache.

Q48. What is Object Repository?

Ans. Object Repository refers to a collection of web elements belonging to Application Under Test (AUT) along with their locator values. Object Repository is used to store locators in a centralized location.

Q49. How can we create Object Repository in Selenium?

Ans. We can create Object Repository in an excel sheet that can be populated inside the script whenever required.

Q50. Does Selenium have any limitations?

Ans. Yes, it has.

  • It supports testing of only web-based applications
  • One cannot test mobile applications
  • Selenium can’t test Captcha and Barcode readers
  • It helps to generate reports using third-party tools like TestNG or JUnit
  • No ready vendor support
  • User must possess programming language knowledge

Q 51. Which browsers/drivers do Selenium WebDriver support?

Ans. Selenium WebDriver supports –

  • Android – Selendroid/Appium
  • Firefox – FireFoxDriver
  • Google Chrome – ChromeDriver
  • HtmlUnit (Headless browser) – HtmlUnitDriver
  • Internet Explorer – InternetExplorerDriver
  • IOS – ios-driver/Appium
  • Safari – SafariDriver

 

Q 52. Does Selenium Webdriver support web services testing?

Ans. Selenium WebDriver automates web applications using the browser’s native method. Therefore, it is not possible to test web services using Selenium WebDriver because they are headless.

Q 53. What is an absolute XPath?

Ans. Absolute XPath locates an element using XML expression that starts from the root node or with ‘/’. It contains the complete path of all the elements, including the root element, as well as the desired element. Absolute XPath has a significant disadvantage, which is if there is even a minor change in the UI, the entire XPath fails.

Q 54. What is a Relative XPath?

Ans. Relative XPath locates an element using XML expression, beginning from anywhere in the HTML document. This is used to create robust XPaths, which remain unaffected by changes in other UI elements.

Q 55. Mention the basic difference between single slash(/) and double slash(//) in XPath?

Ans. In XPath –

A single slash is used to create XPath with absolute XPaths

A double slash is used to create XPath with relative XPaths.

Q 56. How to use CSS Selector for identifying web elements by class?

Ans. To identify web elements by their class, we can use .className and select elements belonging to that particular class. Apart from this, a CSS selector can locate web elements with ID, class, or name.

Q 57. How to use CSS Selector for identifying web elements by ID?

Ans. To identify web elements by ID, we can use #idValue and select elements belonging to that particular ID.

Q 58. How to use CSS Selector for identifying web elements by their attribute value?

Ans. To identify web elements by their attribute value, we can use [attribute=value] to select elements belonging to that particular attribute type.

Q 59. How can we move to nth child element using CSS Selector?

Ans. We can use :nth-child(n) to move to the nth child element.

Q 60. Explain the difference between XPath and CSS Selector.

Ans. In XPath, we can traverse both forward and backward, while CSS selector moves forward only.

Q 61. What type of tests have you automated?

Ans. Your reply should be specific here. You should focus on how you automate test cases to do Regression testing, Smoke testing, and Sanity testing. You can also mention that you have done End to End testing, basis project, and test time estimation.

Q 62. Can we launch different browsers in Selenium WebDriver? How?

Ans. Yes, we can launch different browsers in Selenium WebDriver by creating an instance of the driver of the particular browser.

Q 63. How to check a checkBox in selenium?

Ans. One can select a checkBox the way a button is clicked.

driver.findElement(By.id(“idOfTheElement”)).click();

Toggling a check box on/off can also be done using the click() method, and isSelected() method is used to check if the Checkbox is toggled on or off.

Q 64. Explain the difference between driver.getWindowHandle() and driver.getWindowHandles() in selenium.

Ans.

driver.getWindowHandle() is a unique identifier and it returns a handle of the current page

driver.getWindowHandles() returns a set of handles of the all the available pages

Q 65. What are some possibilities of using conditions in Explicit waits?

Ans. The most common possibilities are –

elementToBeClickable(WebElement element or By locator)

stalenessOf(WebElement element)

visibilityOf(WebElement element)

visibilityOfElementLocated(By locator)

invisibilityOfElementLocated(By locator)

attributeContains(WebElement element, String attribute, String value)

alertIsPresent()

titleContains(String title)

titleIs(String title)

textToBePresentInElementLocated(By, String)

 Q 66. What are DesiredCapabilities in Selenium WebDriver?

Ans. DesiredCapabilities are a set of key-value pairs that help to set properties for the WebDriver. This helps to set the specific properties of browsers such as browser name, platform, and version of the browser, in the browser instances.

Q 67. What is data driven framework?

Ans. Data-driven is a test automation framework. It stores test data in a spread spreadsheet or table format such as MS Excel Sheets, MS Access Tables, SQL Database, XML files etc. separated from test logic written in test script files. Data Driven Testing enables engineers to execute tests for each set of test data values.

Q 67. What is a keyword driven framework?

Ans. A keyword-driven framework is a type of Functional Automation Testing Framework, and it works on action word based testing. The keyword-driven framework helps to accelerate automated testing by using keywords related to the application being tested. These keywords should be included in every input to describe actions to be performed for each step and execute the test successfully.

Q 68. What is a hybrid framework?

Ans. As the name suggests, a hybrid framework is a combination of one or more frameworks and is a combination of data-driven and keyword-driven frameworks. Here the test data and test actions are kept in external files. This implements the Page Object Model Technique, Data Driven Technique, Modular Driven Technique, Log4j Logging, TestNG Reporting, and TestNG Reporter Logs.

Q 69. What is Selenium 2.0, and how is it better than Selenium 1.0?

Ans. Selenium 1 is known as Selenium Remote Control (RC). Selenium 2.0 is a combination of Selenium 1 and WebDriver, making it superior to RC. Selenium 2 is also popularly known as Selenium WebDriver that directly sends commands to the browser instead of sending it to a server. Selenium 2.0 runs the JavaScript natively; thus there is a need to write the test once, and Selenium will test on different browsers.

Q 70. What is Selenium 3.0, and how is it better than Selenium 2.0?

Ans. There was a major WebDriver upgrade in 2016 and Selenium 3.0 incorporates that upgrade, which includes the W3C specifications for Webdriver APIs.

Q 71. How can we pass parameters to test script using TestNG?

Ans. We can use Parameter annotation and Parameter tag in TestNG.xml to pass parameters to the test script.

New TestNG.xml –

<suite name=”newTestSuite”>

<test name=”newTest”>

<parameter name=”newParamName” value=”newParamValue”/>

<classes>

<class name=”TestFile” />

</classes>

</test>

</suite>

Q 72. Can you explain how can we make two test methods dependent on each other using TestNG?

Ans. There is a feature in TestNG, dependency, which allows a test method to depend on other test methods. Dependency is configured by using the dependent test method separated by commas to the attribute dependsOnMethods. This is done while using test annotation on multiple test methods.

@Test(dependsOnMethods = { “preTests” })

 

Q 73. What is the latest Selenium WebDriver Architecture?

Ans. This block diagram will represent the latest Selenium WebDriver Architecture –

Q 74. What are the different OS/platforms supported by Selenium?

Ans. Different OS/platforms supported by Selenium include –

  • Android
  • IOS
  • Linux
  • Mac OS X
  • Windows Desktop
  • Windows Mobile

Q 75. What types of cases can be automated using Selenium?

Ans. Selenium can be used to automate the following types of cases –

  • Acceptance tests
  • Cross-browser tests
  • End-to-end test cases
  • Functional cases
  • Integration tests
  • Regression test cases
  • Responsiveness cases
  • Sanity test
  • Smoke testing

These are some of the popular questions asked in Selenium interviews. Always be prepared to answer all types of questions — technical skills, interpersonal, leadership or methodology. If you are someone who has recently started your career in software testing, you can always get certified in Selenium to get the requisite technical skills and experience.

About the Author

Hasibuddin Ahmed

Hasibuddin Ahmed

Hasib is a professional writer associated with learning.naukri.com. He has written a number of articles related to technology, marketing, and career on various blogs and websites. As an amateur career guru, he often imparts nuggets of knowledge related to leadership and motivation. He is also an avid reader and passionate about the beautiful game of football.

Comments are closed.