Selenium Interview Questions

Get Technical Answers for Selenium Interview Questions by Selenium Expert Developer, Advanced Technical Questions for Freshers and Experience Persons. Free Practical test

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

The reasons are.

  • Selenium is an open-source tool.
  • It has a large user base and helping communities.
  • It can work with the cross browsing capabilities on Firewall, Chrome, Internet Explorer, Safari etc.
  • It has great platform compatibility which runs on the operating systems such as Windows, Mac OS, Linux etc.
  • Support for multiple programming languages such as Java, C#, Ruby, Python, Pearl etc.
  • It has fresh and regular repository developments.
  • It supports distributed testing.

2. What are the testing types supporting by Selenium?

Selenium support two types of testing.

  1. Functional testing.
  2. Regression testing

Selenium Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

 

3. What are the limitations of Selenium?

The limitations are.

  • It supports the testing only for web-based applications.
  • The mobile applications cannot be tested by Selenium.
  • Captcha and Barcode readers also can’t be tested by Selenium.
  • The reports can be generated only with third-party tools like TestNG or JUnit.
  • The user should possess knowledge of programming languages.

Subscribe to our youtube channel to get new updates..!

 

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

Assert:

The Assert command checks for the condition if true or false. If you assert for an element and want to check if is present in a page or not then the program control will execute the next test if the condition is true else the execution stops and no further test will be executed when the condition becomes false.

Verify:

Verify command also checks for true or false but irrespective of the condition the program execution will not halt. This means any failure during verification won’t stop executing the further test steps.

Selenium Certification Training

Weekday / Weekend Batches

 

5. How do I launch the browser using WebDriver?

The following syntax is used in launching the Browser.

WebDriver driver = new FirefoxDriver();

WebDriver driver = new ChromeDriver();

WebDriver driver = new InternetExplorerDriver();

6. Explain the difference between single and double slash in X-path?

Single slash ‘/ ’:

  • The single slash ( / ) will start the selection from the document node.
  • It allows users to create “absolute” path expressions.

Double Slash ‘// ’:

  • The Double slash ( // ) will start the selection matching anywhere in the document.
  • It enables users to create “relative” path expressions.

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

 WebDriver has two types of waits.

       1.Implicit: These are used to provide default waiting time say 30 seconds for consecutive test commands across the entire test script. This subsequent step would execute when 30 seconds have elapsed after executing the previous step/command.

       2.Explicit: These are used to halt the execution when it reaches its maximum time for elapsing or when a particular condition is met. These waits are applied only for a particular instance.

8. How can you find if an element is displayed on the screen?

To the visibility of web elements, the WebDriver facilitates the user with the following web elements that can be buttons, drop boxes, checkboxes, radio buttons, labels etc. The methods are.

  1. isDisplayed()
  2. isSelected()
  3. isEnables()

Syntax:

isDisplayed():

boolean buttonPresence = driver.findElement(By.id(“gbqfba”)).isDisplayed();

isSelected():

boolean buttonSelected = driver.findElement(By.id(“gbqfba”)).isSelected();

isEnabled():

boolean searchIconEnabled = driver.findElement(By.id(“gbqfb”)).isEnabled();

9. How to select value in a dropdown?

The values are selected using WebDriver’s select class.

Syntax selectByValue:

Select selectByValue = new Select(driver.findElement(By.id(“SelectID_One”)));

selectByValue.selectByValue(“greenvalue”);

selectByVisibleText:

Select selectByVisibleText = new Select (driver.findElement(By.id(“SelectID_Two”)));

selectByVisibleText.selectByVisibleText(“Lime”);

selectByIndex:

Select selectByIndex = new Select(driver.findElement(By.id(“SelectID_Three”)));

selectByIndex.selectByIndex(2);

10. What is the difference between single and double slash in X-path?

Single slash ‘/’

  • It starts selection from the document node.
  • Single slash allows you to create ‘absolute’ path expressions.

Double slash ‘//’

  • It starts selection matching anywhere in the document.
  • Double slash enables to create ‘relative’ path expressions.

11. Why testers should opt for Selenium and not for QTP?

QTP is a commercial tool while Selenium is open-source.

  • Selenium is tested only on web applications while QTP can test client-server applications also.
  • Selenium is supported by web browsers such as Firefox, IE, Opera, Safari on operating systems like Windows, Mac, Linux etc but QTP is only limited to Internet Explorer on Windows.
  • Selenium is supported by programming languages such as Ruby, Pearl, Python while QTP supports only VB script.

12. How do you handle web-based pop-up?

The pop-ups are handled using the Alert interface of WebDriver. These four methods used along with Alert interface. 

void dismiss() - This method clicks the “Cancel” button when the pop-up window appears.

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

String getText() - This method returns the text which is displayed on the alert box.

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

Syntax:

// accepting javascript alert

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

alert.accept();

13. What are the four parameters that must be passed in Selenium?

The parameters are.

  1. Host.
  2. Port Number.
  3. Browser.
  4. URL.

14. What is the difference between setSpeed() and sleep() method?

Both methods delay the execution speed.

thread.sleep(): It stops the current java thread for a specific time period. It can be done only once.

  • It takes the single argument in an integer format.

Example: thread.sleep(2000)- It will wait for 2 seconds.

  • It will wait only for once at the command given at sleep.

setSpeed(): It stops the execution for a specific time period for every selenium command.

  • It takes the single argument in an integer format.

Example: selenium.setSpeed(“2000”)- It will wait for 2 seconds.

  • It runs each command after setSpeed delay by the number of milliseconds mentioned in set Speed.

The setSpeed() is useful in demonstrating or while using a slow web application.

15. What Are The Advantages And Disadvantages Of Selenium ?

Advantages

The advantages are:

  • Support for multiple programming languages such as C#, PHP, Java, Perl, Python.
  • Support for different operating systems like Windows, Linux and Mac OS.
  • Implements the powerful methods for locating the Xpath, DOM, CSS elements.
  • Selenium has a large developer community supported by Google.

Disadvantages:

  • Challenges running on browsers other than Firefox
  • Difficulty to automate AJAX
  • Limitations to automate Applets, MS and Desktop Applications

16. How can you retrieve the CSS properties of an element?

The CSS property values are retrieved using the get() method.

Syntax:

driver.findElement(By.id(“id“)).getCssValue(“name of css attribute”);

driver.findElement(By.id(“id“)).getCssValue(“font-size”);

17. What is the difference between “findElement()” and “findElements()”?

findElement():

  • It finds the first element within the current page by using “locating mechanism”.
  • The method returns a single WebElement.

findElements():

  • By using the “locating mechanism” this method finds all elements within a current page.
  • The method returns a list of web elements.

18. How to mouse hover on a web element using a web driver?

WebDriver offers a wide range of interaction utilities for users who can also exploit the events of mouse automation and keyboard. Action interface is one utility which simulates the single user interactions.
In this scenario, we use the Action interface to mouse hover on a drop to open a list of options.
Sample Code:

// Instantiating Action Interface
Actions actions=new Actions(driver);
// howering on the dropdown
actions.moveToElement(driver.findElement(By.id("id of the dropdown"))).perform();
// Clicking on one of the items in the list options
WebElement subLinkOption=driver.findElement(By.id("id of the sub link id"));
subLinkOption.click();

19. Explain the Data-driven and Keyword-driven frameworks.

Data-driven framework:
In this framework, the test data will be separated and are kept outside the Test Scripts while the logic of Test Case resides inside the Test Scripts. The Test data will be read from external excel files and are loaded into the variables of Test Script. Variables are used for both input and verifications values.

Keyword-driven framework:
This framework requires the development of data tables and keywords that are independent of test automation. In this test, the functionality of an application in the test will be documented in a table as well as step by step instructions for each test.

20. Mention the five different exceptions you had in Selenium WebDriver.

The five exceptions in Selenium are.

  • WebDriverException
  • NoAlertPresentException
  • NoSuchWindowException
  • NoSuchElementException
  • TimeoutException

21. What Are The Technical Challenges With Selenium?

 The challenges faced by Selenium are.

  • Having support only for web-based applications.
  • Unsupported for Bitmap comparison.
  • The reporting capabilities depend on third-party tools.
  • No vendor supported for commercial tools like HP UFT.
  • There exists no object repository concept in Selenium and maintenance is difficult.

22. Explain how can you switch between frames.

For switching between the frames, the web drivers “driver.switchTo().frame()” takes one of the three possible arguments.
A number: It selects the number by its index which is zero-based.
A name or ID: Select a frame by its name or ID.
Previously found WebElement: Selecting a frame by using its previously located WebElement.

23. What is the difference between “getWindowHandles()” and “getWindowHandle()”?

getWindowHandles(): The method is used to get the address of all open browser. The return type of this method is Set.
getWindowHandle(): The method is used to get the address of the current browser and the return type of this method is a string.

24. What is the difference between POI and jxl jar?

JXL jar:

  • JXL supports binary-based formats such as “.xls”. It doesn’t support Excel 2007 of “.xlsx” format which is based on XML.
  • The last updated year of JXL API is 2009.
  • The JXL documentation is not that comprehensive as compared to POI.
  • The rich text formatting is not supported by JXL API.
  • JXL API performs faster than the POI API.

POI jar:

  • POI supports all the formats.
  • POI is updated and released regularly.
  • The POI documentation is well prepared and highly comprehensive.
  • The rich text formatting is supported by POI API.
  • POI API performance is slow as compared to JXL API.

25. What is an object repository? How do you create an object repository in Selenium?

Object repository is a term that is used while referring to the collection of web elements which belongs to an Application Under Test (AUT) and its locator values. When an element is required in the script, the locator value is populated from the object repository. Object repository is used for storing the locators in a centralized location instead of hardcoding them within the scripts.
In Selenium, the objects are stored in an excel sheet which can be populated inside the script whenever it is required.

26. List out different types of locators?

The different types of locators are.

By.id()

  • By.name()
  • By.tagName()
  • By.className()
  • By.linkText()
  • By.partialLinkText()
  • By.xpath
  • By.cssSelector()

27. What are the features of TestNG and list some of the functionality in TestNG which make it more effective?

TestNG is a testing framework that is based on JUnit and NUnit which simplifies a broad range of testing needs from unit testing to integration testing. The effective testing framework functionalities are.

Providing support for annotations.

  • Providing support for data-driven testing.
  • Flexibility in the test configuration.
  • The ability of re-executing the failed test-cases.

28. How do you set test case priority in Testing?

The following code explains how to set priority in TestNG.
Code Snippet:

package TestNG;
import org.testng.annotations.*;
public class SettingPriority {
@Test(priority=0)
public void method1() {
}
@Test(priority=1)
public void method2() {
}
@Test(priority=2)
public void method3() {
}
}
Test Execution Sequence:
Method1
Method2
Method3

29. What are the capabilities of Selenium WebDriver or Selenium 2.0?

WebDriver is used when improvement support is required. The capabilities are of WebDriver includes.

Ability to handle multiple frames, pop-ups, multiple browser windows and alerts.

  • Page navigation support and drag & drop interactions.
  • UI elements based on Ajax.
  • Multi-browser testing including improved functionality for the browser which is not well supported by Selenium 1.0

30. How Do You Verify An Object Presented In Multiple Pages?

Check on each page
assertTrue(selenium.isElementPresent(locator));

31. How Do You Capture An Element Loading After The Page Load?

provide a time to check the element( in seconds) Like :

public void waitForElementPresent(String element, int timeout) throws Exception
{
for (int second = 0;; second++)
{
if (second >= timeout)
fail("Timeout.Unable to find the Specified element"+element);
try
{
if (selenium.isElementPresent(element)) break;
}
catch (Exception e) { }
Thread.sleep(1000);
}
}

32. What Is Selenium ?

  • Selenium is a portable software testing framework for web applications.
  • The tests can be written as HTML tables or coded in a number of popular programming languages and can be run directly in most modern web browsers.
  • Selenium operations are highly flexible, allowing many options for locating UI elements and comparing expected test results against actual application behavior.
  • Selenium can be deployed on Windows, Linux, and Macintosh.
  • Selenium is used for UAT (User Acceptance Test)

33. Why And When To Automate?

  • Frequent regression testing
  • Repeated test case Execution is required
  • User Acceptance Tests
  • Faster Feedback to the developers
  • Reduce the Human Effort
  • Test same application on multiple environments

34. What Are The Components Of Selenium ?

  • Selenium IDE
  • Selenium Remote Control
  • Selenium Grid

35. Explain About Selenium-ide ?

  • Selenium IDE is an integrated development environment for Selenium tests.
  • Operates as a Firefox add-on and provides an interface for developing and running individual test cases or entire test suites.
  • Selenium-IDE has a recording feature, which will keep account of user actions as they are performed and store them as a reusable script to play back.
  • It also has a context menu (right-click) integrated with the Firefox browser, which allows the user to pick from a list of assertions and verifications for the selected location.
  • Offers full editing of test cases.
  • Although it is a Firefox only add-on, tests created in it can also be run against other browsers by using Selenium-RC & specifying the name of the test suite on the command line.

36. What Are The Features Of Selenium Ide ?

  • Record and playback
  • Intelligent field selection will use IDs, names, or XPath as needed
  • Auto complete for all common Selenium commands
  • Walk through test cases and test suites.
  • Debug and set breakpoints
  • Save texts as HTML, Ruby scripts, or other formats
  • Support for Selenium user-extensions.js file
  • Option to automatically assert the title of every page
  • Rollup common commands

37. What Is Selenium-rc (remote Control) ?

Selenium-RC provides an API (Application Programming Interface) and library for each of its supported languages: HTML, Java, C#, Perl, PHP, Python, and Ruby. Selenium-RC allows the test automation developer to use a programming language for maximum flexibility and extensibility in developing test logic.

For instance, if the application under test returns a result set, and if the automated test program needs to run tests on each element in the result set, the programming languages iteration support can be used to iterate through the result set, calling Selenium commands to run tests on each item.

38. Explain About Selenium-grid ?

Selenium-Grid allows the Selenium-RC solution to scale for test suites or test suites to be run in multiple environments.
With Selenium-Grid multiple instances of Selenium-RC are running on various operating system and browser configurations, each of these when launching register with a hub. When tests are sent to the hub they are then redirected to an available Selenium-RC, which will launch the browser and run the test.
This allows for running tests in parallel, with the entire test suite theoretically taking only as long to run as the longest individual test.

39. What Are The Selenese Commands In Selenium ?

  • clicking a link - click or clickAndWait commands
  • entering values - type command
  • selecting options from a drop-down listbox - select command
  • clicking checkboxes or radio buttons - click command

40. What Is Test Runner ?

Test Runner allows you to run the test case in a browser loaded with the Selenium-Core TestRunner. Test runner is invoked by clicking the below Shown button in the IDE.

41. What Are The Running Options In Selenium ?

Run a Test Case: Click the Run button to run the currently displayed test case.
Run a Test Suite: Click the Run All button to run all the test cases in the currently loaded test suite.
Stop and Start: The Pause button can be used to stop the test case while it is running. The icon of this button then changes to indicate the Resume button. To continue click Resume.
Stop in the Middle: Set a breakpoint in the test case to cause it to stop on a particular command. This is useful for debugging your test case. To set a breakpoint, select a command, right-click, and from the context menu select Toggle Breakpoint.
Start from the Middle: We can set the IDE to begin running from a specific command in the middle of the test case. This also is used for debugging. To set a start point, select a command, right-click, and from the context menu select Set/Clear Start Point.
Run Any Single Command: Double-click any single command to run it by itself. This is useful when writing a single command. It lets you immediately test a command you are constructing, when you are not sure if it is correct. You can double-click it to see if it runs correctly. This is also available from the context menu.

42. What Are The Assertion Statements In Selenium ?

  • assertTextPresent : This will assert if the text is present in the page.
  • assertText: This will assert if a particular element is having the particular text.
  • assertTitle: This will assert if the page is having a proper title.
  • assertValue: This will assert if a Text box or check box has a particular value
  • assertElementPresent: This will assert if a particular UI Element is present in the page.

43. Explain Selenium Waitfor Commands ?

waitForPageToLoad : This command will make the script to wait till the page loads.Syntax is waitForPageToLoad(timeout); Timed out is the maximum time the script will wait for the page to load.
waitForAlert : This command will wait for the alert message to appear
waitForTable: This command will wait for the Web table to completely load in the page
waitForTitle: This command will for the page Title to appear on the browser.
Other waitFor commands : Selenium has several other wait command like waitForText,waitForPopup and so on. These commands are generically called Synchronization commands

44. What Is Selenium Ide?

Selenium IDE is an integrated development environment for Selenium tests. It is implemented as a Firefox extension, and has a recording feature, which will keep account of user actions as they are performed and store them as a reusable script to play back. Selenium-IDE also offers full editing of test cases for more precision and control.

45. Selenium Test A Application On Iphone Mobile Safari Browser?

Selenium can handle Mobile Safari browser. There is experimental Selenium IPhone Driver for running tests on Mobile with Safari on the iPhone and iPad and iPod Touch.

46. Can Selenium Test An Application On Android Browser?

Selenium can handle Android browser.

47. How To Start The Selenium Server From Your Language Class?

try {
seleniumServer = new SeleniumServer();
seleniumServer.start();
} catch (Exception e) {
e.printStackTrace();
}

48. But My Tests Need Me To Exercise Objects Outside Browser, How Do I Achieve It?

You can use Robot class in java to achieve this, but it would be dirty solution even if you get through this.

49. How To Run Test Case Recorded Using Selenium Ide In Other Browsers?

Running test case recorded with the help of Selenium Remote Control.

50. What Is The Selenium's Recording Language?

Selenium’s recording language is “HTML”.

51. What Are The Steps To Run Automation Using Selenium?

The very basic steps are:

Record the test steps using selenium-IDE.

  • Modify the script according to the testing needs. Add validation points, Java Scripts, Time-out etc.
  • Run the test.
  • View the result after test run complete analyze.

52. What Are The Capabilities Of Selenium Ide?

Selenium IDE (Integrated Development Environment) works similar to commercial tools like QTP, Silk Test and Test Partner etc. The below points describes well about Selenium IDE.

  • Selenium IDE is a Firefox add-on.
  • Selenium IDE can support recording the clicks, typing, and other actions to make a test cases.
  • Using Selenium IDE, a tester can play back the test cases in the Firefox browser.
  • Selenium IDE supports exporting the test cases and suites to Selenium RC.
  • Debugging of the test cases with step-by-step can be done.
  • Breakpoint insertion is possible.
  • Page abstraction functionality is supported by Selenium IDE.
  • Selenium IDE can supports an extensibility capability allowing the use of add-ons or user extensions that expand the functionality of Selenium IDE.

53. Describe Technical Problems That You Had With Selenium Tool?

As with any other type of test automation tools like SilkTest, HP QTP, Watir, Canoo Webtest, Selenium allows to record, edit, and debug tests cases. However there are several problems that seriously affect maintainability of recorded test cases, occasionally Quality Assurance Engineers complain that it takes more time to maintain automated test cases than to perform manual testing; however this is an issue with all automated testing tools and most likely related to improper testing framework design. Another problem is complex ID for an HTML element. If IDs is auto-generated, the recorder test cases may fail during playback. The work around is to use XPath to find required HTML element. Selenium supports AJAX without problems, but QA Tester should be aware that Selenium does not know when AJAX action is completed, so ClickAndWait will not work. Instead QA tester could use pause, but the snowballing effect of several 'pause' commands would really slow down total testing time of test cases. The best solution would be to use waitForElement.

54. What Test Can Selenium Do?

Selenium could be used for the functional, regression, load testing of the web based applications. The automation tool could be implemented for post release validation with continuous integration tools like Jenkins, Hudson, QuickBuild or CruiseControl.

55. What Is The Price Of Selenium License Per Server?

Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.

56. How Much Does Selenium License Cost Per Client Machine?

Selenium is open source software, released under the Apache 2.0 license and can be downloaded and used without charge.

57. Where To Download Selenium?

Selenium can be downloaded and installed for free from seleniumhq.org

Submit an interview question

Categories

Request for more information

John
John
Cloud Technologies & Cyber Security
John is a Post Graduate in Computer Science from Andhra University .She is currently working as an IT developer at hkr trainings.com. And he has great experience includes both IT development and operational roles. Connect with him on LinkedIn and Twitter. Thank you

WhatsApp
To Top