SELENIUM INTERVIEW QUESTIONS – 1

 

  1. What is Automation Testing?

  • Automation testing is a process of automating the manual process to test the application/system under test.
  • Automation testing involves use to a separate testing tool which lets you create test scripts which can be executed repeatedly and doesn’t require any manual intervention.
  • Automated testing tools are capable of executing tests, reporting outcomes and comparing results with earlier test runs.

 

  1. What are the benefits of Automation Testing?

  • Supports execution of repeated test cases.
  • Enables parallel execution.
  • Improves accuracy thereby reducing human-generated errors.
  • Saves time and money.
  • Increased throughput or productivity.
  • Improved quality or increased predictability of quality.
  • Improved robustness of processes or product.
  • Increased consistency of output.
  • Reduced direct human labor costs and expenses.

 

  1. Why should Selenium be selected as a test tool?

  • Selenium is pure open source, freeware and portable tool.
  • Selenium have a large user base and helping communities.
  • Selenium have cross Browser compatibility (Firefox, Chrome, Internet Explorer, Safari etc.).
  • Selenium have great platform compatibility (Windows, Mac OS, Linux etc.).
  • Selenium supports multiple programming languages (Java, C#, Ruby, Python, Pearl etc.).
  • Selenium has fresh and regular repository developments.
  • Selenium supports distributed testing.

 

  1. What is Selenium? What are the different Selenium components?

  • Selenium is one of the most popular automated testing suites.
  • Selenium is designed in a way to support and encourage automation testing of functional aspects of web-based applications and a wide range of browsers and platforms.
  • Due to its existence in the open source community, it has become one of the most accepted tools amongst the testing professionals.

Components of Selenium:

  1. Selenium IDE
  2. Selenium RC
  3. Selenium WebDriver
  4. Selenium Grid
  • Selenium Integrated Development Environment (IDE):– Selenium IDE is a record and playback tool. It is distributed as a Firefox Plugin.
  • Selenium Remote Control (RC):– Selenium RC is a server that allows a user to create test scripts in the desired programming language. It also allows executing test scripts within the large spectrum of browsers.
  • Selenium WebDriver: – WebDriver is a different tool altogether that has various advantages over Selenium RC. WebDriver directly communicates with the web browser and uses its native compatibility to automate.
  • Selenium Grid: – Selenium Grid is used to distribute your test execution on multiple platforms and environments concurrently.

 

  1. What are the testing types that can be supported by Selenium?

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

 

  1. What are the limitations of Selenium?

  • Selenium supports testing of only web-based applications.
  • Mobile applications cannot be tested using Selenium.
  • Captcha and Barcode readers cannot be tested using Selenium.
  • Reports can only be generated using third-party tools like TestNG or JUnit.
  • As Selenium is a free tool, thus there is no ready vendor support though the user can find numerous helping communities.
  • The user is expected to possess prior programming language knowledge.

 

  1. What are the different types of locators in Selenium?

The locator can be termed as an address that identifies a web element uniquely within the webpage.

  1. ID
  2. ClassName
  3. Name
  4. TagName
  5. LinkText
  6. PartialLinkText
  7. Xpath
  8. CSS Selector
  9. DOM

 

  1. What the difference between assert and verify commands?

Assert: Assert command checks whether the given condition is true or false.

  • Let’s say we assert whether the given element is present on the web page or not.
  • If the condition is true then the program control will execute the next test step but if the condition is false, the execution would stop and no further test would be executed.

 

Verify: Verify command also checks whether the given condition is true or false.

  • Irrespective of the condition being true or false, the program execution doesn’t halt i.e. any failure during verification would not stop the execution and all the test steps would be executed.

 

  1. What is an XPath?

  • XPath is used to locate a web element based on its XML path.
  • XML stands for Extensible Markup Language and is used to store, organize and transport arbitrary data.
  • It stores data in a key-value pair which is very much similar to HTML tags.

 

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

  • Single Slash “/”:– Single slash is used to create Xpath with absolute path i.e. the xpath would be created to start selection from the document node/start node.
  • Double Slash “//”:– Double slash is used to create Xpath with relative path i.e. the xpath would be created to start selection from anywhere within the document.

 

  1. When should I use Selenium Grid?

  • Selenium Grid can be used to execute same or different test scripts on multiple platforms and browsers concurrently so as to achieve distributed test execution, testing under different environments and saving execution time remarkably.

 

  1. How do I launch the browser using WebDriver?

The following syntax can be used to launch Browser: 

 

  1. What are the different types of Drivers available in WebDriver?

The different drivers available in WebDriver are:

  • FirefoxDriver
  • InternetExplorerDriver
  • ChromeDriver
  • SafariDriver
  • OperaDriver
  • AndroidDriver
  • IPhoneDriver
  • HtmlUnitDriver

 

  1. What are the different types of waits available in WebDriver?

There are two types of waits available in WebDriver:

  • Implicit Wait
  • Explicit Wait

 

  • Implicit Wait: Implicit waits are used to provide a default waiting time (say 30 seconds) between each consecutive test step/command across the entire test script. Thus, subsequent test step would only execute when the 30 seconds have elapsed after executing the previous test step/command.

 

  • Explicit Wait: Explicit waits are used to halt the execution till the time a particular condition is met or the maximum time has elapsed. Unlike Implicit waits, explicit waits are applied for a particular instance only.

 

  1. Handle textbox using Selenium?

  • User can use sendKeys(“String_Name”) to enter the string in the textbox.

Syntax: 

 

  1. How can you find if an element in displayed on the screen?

WebDriver facilitates the user with the following methods to check the visibility of the web elements. These web elements can be buttons, drop boxes, checkboxes, radio buttons, labels etc.

  • isDisplayed()
  • isSelected()
  • isEnabled()

Syntax:

 

  1. How can we get a text of a web element?

  • Get command is used to retrieve the inner text of the specified web element.
  • The command doesn’t require any parameter but returns a string value.
  • It is also one of the extensively used commands for verification of messages, labels, errors etc. displayed on the web pages.

Syntax: 

 

  1. How to select value in a dropdown?

  • Value in the drop down can be selected using WebDriver’s Select class.

Syntax:

 

  1. What are the different types of navigation commands?

Following are the navigation commands:

  •  navigate().back():– The above command requires no parameters and takes back the user to the previous webpage in the web browser’s history.

 

  • navigate().forward():– This command lets the user to navigate to the next web page with reference to the browser’s history.

 

  • navigate().refresh()– This command lets the user to refresh the current web page there by reloading all the web elements.

 

  • navigate().to()– This command lets the user to launch a new web browser window and navigate to the specified URL.

 

  1. How to click on a hyper link using linkText?

  • The command finds the element using link text and then click on that element and thus the user would be re-directed to the corresponding page.

 

  1. How to handle Iframe in WebDriver?

  • iFrame is a HTML document embedded inside an HTML document.
  • iFrame is defined by an <iframe></iframe> tag in HTML.

 

  1. When do we use findElement() and findElements()?

 

findElement(): findElement() is used to find the first element in the current web page matching to the specified locator value. Take a note that only first matching element would be fetched.

Syntax:

 

findElements(): findElements() is used to find all the elements in the current web page matching to the specified locator value. Take a note that all the matching elements would be fetched and stored in the list of WebElements.

Syntax:

 

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

  • Sometimes we have need to fetch multiple links / images / records to verify particular record is exist or not?

Sample Code:

 

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

  • close (): WebDriver’s close() method closes the currently working or currently access window by WebDriver.
  • quit (): Unlike close() method, quit() method closes down all the windows that the program has opened.

 

  1. How can we handle web based pop up?

WebDriver handle pop up using Alert interface.

Four methods that we would be use along with the Alert interface.

  • void accept()– The accept() method clicks on the “Ok” button as soon as the pop up window appears.
  • void dismiss()– The dismiss() method clicks on the “Cancel” button as soon as 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: 

 

  1. How can we handle windows based pop up?

  • There are several third party tools available for handling window based pop ups along with the selenium like AutoIT, Robot class etc.

 

  1. How to mouse hover on a web element using WebDriver?

  • Using Action Interface to mouse hover on a drop down which then opens a list of options.

Sample Code:

 

  1. How to retrieve css properties of an element?

  • The values of the css properties can be retrieved using a get() method:

Syntax: 

 

  1. What is a framework?

  • Framework is a constructive blend of various guidelines, coding standards, concepts, processes, practices, project hierarchies, modularity, reporting mechanism, test data injections etc. to pillar automation testing.

 

  1. What are the advantages of Automation framework?

Advantage of Test Automation framework

  • Reusability of code.
  • Maximum coverage.
  • Recovery scenario.
  • Low cost maintenance.
  • Minimal manual intervention.
  • Easy Reporting.

 

  1. What are the different types of frameworks?

  • Data Driven Testing Framework: Data Driven Testing Framework helps the user segregate the test script logic and the test data from each other. It lets the user store the test data into an external database. The data is conventionally stored in “Key-Value” pairs. Thus, the key can be used to access and populate the data within the test scripts.

 

  • Keyword Driven Testing Framework: The Keyword driven testing framework is an extension to Data driven Testing Framework in a sense that it not only segregates the test data from the scripts, it also keeps the certain set of code belonging to the test script into an external data file.

 

  • Hybrid Testing Framework: Hybrid Testing Framework is a combination of more than one above mentioned frameworks. The best thing about such a setup is that it leverages the benefits of all kinds of associated frameworks.

 

  • Behavior Driven Development Framework: Behavior Driven Development framework allows automation of functional validations in easily readable and understandable format to Business Analysts, Developers, Testers, etc.

 

  1. Can captcha be automated?

  • No, captcha and bar code reader cannot be automated.

 

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

  • 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.
  • Thus, whenever the element is required within the script, the locator value can be populated from the Object Repository.
  • Object Repository is used to store locators in a centralized location instead of hard coding them within the scripts.
  • In Selenium, objects can be stored in an excel sheet which can be populated inside the script whenever required.

 

  1. How do you read data from excel?

 

  1. How do you verify if the checkbox/radio is checked or not ?

  •  We can use isSelected() method.

Syntax :

If the return value of this method is true then it is checked else it is not.

 

  1. How do you handle alert pop-up ?

  • To handle alert pop-ups, we need to 1st switch control to alert pop-ups then click on ok or cancle then move control back to main page.

Syntax-

 

  1. How to perform right click using WebDriver?

Ans- Use Actions class

 

  1. How do perform drag and drop using WebDriver?

Ans- Use Action class

 

  1. How do you upload a file?

  • To upload a file we can use sendKeys() method.

 

  1. How do you get the current page URL ?

 

  1. Write the code for Reading and Writing to Excel through Selenium ?

 

  1. How to get typed text from a textbox ?

  • Use getAttribute(“value”) method by passing arg as value.

 

  1. What are the different exceptions you got when working with WebDriver ?

  • ElementNotVisibleException
  • ElementNotSelectableException
  • NoAlertPresentException
  • NoSuchAttributeException
  • NoSuchWindowException
  • TimeoutException
  • WebDriverException

 

  1. What are the languages supported by WebDriver ?

  • Python, Ruby, C# and Java are all supported directly by the development team. There are also webdriver implementations for PHP and Perl.

 

  1. How do you clear the contents of a textbox in selenium ?

Use clear() method.

 

  1. What are the prerequisites to run selenium webdriver?

  • JDK, Eclipse, WebDriver(selenium standalone jar file), browser, application to be tested.

 

  1. How to get the number of frames on a page ?

 

  1. How do you simulate scroll down action ?

Use java script to scroll down-

 

  1. How to check if an element is visible on the web page ?

  • Use isDisplayed() method. The return type of the method is boolean. So if it return true then element is visible else not visible.

 

  1. How to check if a button is enabled on the page ?

  • Use isEnabled() method. The return type of the method is boolean. So if it return true then button is enabled else not enabled.