Top 50 Selenium WebDriver Interview Questions

Refer to the below Links for Practise

Selenium Wiki
Selenium Quiz
Selenium Advanced Quiz
Java Quiz
Java OOPS Quiz
Selenium WebDriver Tester Resume

  1. List the Java Classes available in Selenium API?

  2. Select,ExpectedConditions,RemoteWebDriver,FirefoxDriver,
    ChromeDriver,InternetExplorerDriver,DesiredCapabilities,
    WebDriverWait,Action,Point,Proxy,Rectangle

  3. List the Java Interfaces available in Selenium API?

  4. WebDriver,JavascriptExecutor,TakesScreenshot,WebElement

  5. List the Abstract Class available in Selenium API?

  6. By

  7. List the static methods available in Selenium API?

  8. xpath(),id(),name(),tagName(),linkText(),partialLinkText(),cssSelector()

  9. What is the difference between List & Set?

  10. List is useful to store object which are duplicate as well.
    List list = new ArrayList();
    List list = new Vector();
    List list = new LinkedList();

    • add
    • size
    • get
    • remove(int index)
    • remove(Object o)


    Set is useful to store only unique objects. It doesn’t allow duplicates.
    Set set = new HashSet();
    Set set = new TreeSet();
    Set set = new LinkedHashSet();

    • add
    • size
    • remove(object o)

    Using ITerator or Enhanced for loop to retrieve elements from the Set.

  11. A Class extends more than one class??

  12. Due to diamond problem in java multiple inheritances is not allowed. So, a class can extend only one class at a time as mentioned below.

    Example: public class FirefoxDriver extends RemoteWebDriver

  13. A Interface can extends more than one interface?

  14. Yes. Example: public interface C extends A,B // A & B are interfaces

  15. How to capture the screenshot in Selenium?

  16. File screenshotFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
    String screenshotBase64 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);

  17. How to perform Drag and Drop in Selenium?

  18. Actions action = new Actions(WebDriver);
    action.dragAndDrop(sourceWE, destWE)

  19. What is StaleElementReference Exception?



  20. A stale element reference exception is thrown in one of two cases, the first being more common than the second:

    • The element has been deleted entirely.
    • The element is no longer attached to the DOM. It happens generally when the page is getting refreshed.

    To overcome this either we need to findElement again else we ignore finding the Element which is deleted from DOM. DOM Stands for Document Object Model, the html components are structured in DOM Tree.

  21. What is NullPointerException?

  22. NullPointerException is a RuntimeException . In Java, a special null value can be assigned to an object reference. NullPointerException is thrown when an application attempts to use an object reference that has the null value.
    To overcome this, we need assign the value for the reference variable contains null.
    FirefoxDriver driver; //Contains null value
    driver.get(String url);// throws NullpointerException

    Solution:
    FirefoxDriver driver = new FirefoxDriver();
    driver.get(String url);

  23. What happens when you interact with the Element which is hidden?

  24. org.openqa.selenium.ElementNotVisibleException

  25. What is the difference findElement and findElements?

  26. findElement
    1. WebElement e = driver.findElement(By.name("username"));
    findElement(By) returns an WebElement as a return value.
    2. findElement(By) throws an exception if it is unable to find an Element.
    WebElement e =driver.findElement(By.name(“abc”));
    NoSuchElementException is an RunTimeException/Unchecked Exception
    3. findElement(By) always selects the first one in the list of matching WebElements.
    If we want to select other then frist one, we have to use xpath or cssSelector.
    4 in number.
    driver.findElement(By.tagName(“input”))’ will select first one
    findElements(By)
    1. findElements(By) returns an List of WebElements
    2.findElements(By) returns an empty list if its unable to find an element
    List<WebElement> list = driver.findElements(By.name("abc"));
    Empty List means list.size() is zero.
    3. findElements(By) selects all the matching webElements and returns a list.

  27. Write the logic to get the visibility of the element using JavascriptExecutor?

  28. WebElement element = driver.findElement(By.id(""));
    Object o = ((JavascriptExecutor) driver).
    executeScript("arguments[0].scrollIntoView(true);", element);
    element = (WebElement) o; 
    element.click();

  29. How to retrieve the color of an element?

  30. getCssValue(“color”)
    getCssValue(“background-color”)

  31. How to handle an Alert?

  32. Alert alrt = driver.switchTo().alert();
    alrt.accept();

  33. Write logic to wait an Alert?

  34. WebDriverWait wait = new WebDriverWait(driver,30);
    boolean result = wait.until(ExpectedConditions.isAlertPresent()));

  35. Write logic to wait for an Element?

  36. WebDriverWait wait = new WebDriverWait(driver,30);
    WebElement e=wait.until(ExpectedConditions.visibilityOfElementLocated(By locator));

  37. Write logic to wait for textToBePresent?

  38. WebDriverWait wait = new WebDriverWait(driver,30);
    boolean result = wait.until
    (ExpectedConditions.textToBePresentInElementLocated(By locator,java.lang.String text));

  39. Write logic to wait for title?

  40. WebDriverWait wait = new WebDriverWait(driver,30);
    boolean result = wait.until(ExpectedConditions.titleContains (java.lang.String title));

  41. Write logic to identify element using JavaScriptExecutor?

  42. Object o = ((JavascriptExecutor) driver).executeScript("return document.getElementById(‘idvalue’));
    element = (WebElement) o; 

  43. Write logic to upload a file?

  44. driver.findElement(By.id(“uploadbuttonid”)).sendKeys(“AbsolutePathto File”));

  45. Write logic to copy the file one location to another location?

  46. FileUtils.copyFile(srcLocation,destLocation);

  47. What is the method used to refresh the page?

  48. driver.navigate().refresh();

  49. Write the logic to scroll to a particular element?

  50. (JavascriptExecutor) driver).executeScript(“scroll(height,width)”);

  51. Write the logic to capture the full screenshot using Robot Class?

  52. BufferedImage image = new Robot().
    createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
    ImageIO.write(image, "png", new File("C:\\Screenshot.jpg"));

  53. Write the logic to convert the String to a Double?

  54. String str=”2,567.65”;
    double d = Double.parseDouble(str.replace(“,”,””));

  55. Write the logic to convert the String to a Integer?

  56. String str=”2,567”;
    int d = Integer.parseInteger(str.replace(“,”,””));

  57. Write the logic to verify Element is Enabled?



  58. WebElement e = driver.findElement();
    boolean result = e.isEnabled();

  59. Write the logic to verify the Element is visible?

  60. WebElement e = driver.findElement();
    boolean result = e.isDisplayed();

  61. Write the logic to check if radio/checkbox is Selected?

  62. WebElement e = driver.findElement();
    boolean result = e.isSelected();

  63. What are the different Components of Selenium?
    • Selenium IDE[Integrated Development Environment]
    • Selenium RC[Remote Control]
    • Selenium WebDriver
    • Selenium Grid[Useful to invoke the browser on a remote desktop without copying the source code]

  64. What is the usage of HtmlUnitDriver?

  65. Useful to simulate the behavior of the browser. This helps to execute the scripts without launching the browser.

  66. What is the method used to delete all the cookies in Selenium?

  67. driver.manage().deleteAllCookies();

  68. What is the method used to perform right click in Selenium?

  69. Actions contextClick(WE);

  70. What is method used to perform double click in Selenium?

  71. Actions doubleClick(WE);

  72. What is the difference between click and submit in Selenium?

  73. If this current element is a form, or an element within a form, then this will be submitted to the remote server.
    Else use click method to perform operation on a button.

  74. What is the difference between linkText and PartialLinkText?

  75. LinkText-locates A elements by the exact text they display.
    PartialLinkText-locates A elements that contain the given text.

  76. List all the Exception which come across in Selenium?

  77. NoSuchElementException
    NoSuchFrameException
    NoSuchWindowException
    AlertNotPresentException
    StaleElementReferenceException
    ElementNotVisibleException

  78. What are the Challenges in Selenium?

  79. Identification of Locators.
    Execution of tests against multiple browsers
    Designing the Framework
    Handling wait statements

  80. What is the method used to get all the items in the List?

  81. Select select = new Select(WebElement);
    List<WebElement> itemsList= select.getOptions();

  82. What is the advantage of writing WebDriver driver = new FirefoxDriver();

  83. WebDriver is an Interface and implemented by FirefoxDriver Class.
    During cross browser testing for executing the same tests against the multiple browser.
    We declare the left hand side variable as WebDriver and Right hand side create an object for particular
    type of browser and assign.
    WebDriver driver;
    driver = new FirefoxDriver();
    driver = new ChromeDriver();
    driver = new InternetExplorerDriver();

  84. What is the default port of Selenium Hub ??

  85. Default port is 4444

  86. Write the logic to configure the poll time out?

  87. // Waiting 30 seconds for an element to be present on the page, checking
    // for its presence once every 5 seconds.
    Wait<WebDriver> wait = new FluentWait<WebDriver>(driver)
    .withTimeout(30, SECONDS)
    .pollingEvery(5, SECONDS)
    .ignoring(NoSuchElementException.class);
    WebElement foo = wait.until(ExpectedConditions.visibilityOfElementLocated(By locator));

  88. How to debug the code in Selenium?

  89. By inserting the breakpoint and debug the code in Eclipse.
    (Step Into) go into that method and continue debugging step-by-step.
    (Step Over) to execute that method completely as one entire step without getting into that method

  90. What is mandatory method called to perform sequence of mouse Actions?

  91. perform() method to be called in the end to perform sequence of mouse actions.

  92. What is the method used to get the “id” value of an WebElement?



  93. WebElement e = driver.findElement();
    String idValue = e.getAttribute(“id”);

  94. Is it possible to verify the image?

  95. No. In Selenium we cannot verify the contents of the image but we can verify the image displayed or not by using the properties. Same is applicable for BarCode and captcha images as well.

  96. Is it possible automating Windows Dialog in Selenium?
  97. No. We have to use AutoIT to handle windows Dialogs.

  98. List all the different navigation methods in Selenium?

driver.navigate().to(String url);
driver.navigate().refresh();
driver.navigate().foward();
driver.navigate().back();