Top 25 Mostly Asked Selenium Automation Interview Questions

In this tutorial, we have focused the top most commonly asked Selenium Automation Interview questions and answers including Selenium IDE Selenium Grid and Selenium WebDriver interview questions.

Following are frequently asked questions in real time interviews for freshers as well experienced Selenium Tester.

What is Selenium?

Selenium is a web based application open source, functional and regression testing tool. Selenium supports most of the languages like Java, PHP, Python, Perl, Ruby etc. It is the open source or free version tool so become one of the most accepted tools amongst the testing professionals. It is the combination of different testing tools like Selenium IDE, Selenium RC, WebDriver and Selenium Grid.

What is Selenese?

Selenese is the set of selenium commands which are mostly test your web application. Tester can test the broken links, existence of some object on the UI, Ajax functionality, Alerts, window, list options and lot more using Selenese.
Selenium commands, also referred to as Selenese are the set of commands utilized in Selenium IDE that run your tests. A sequence of Selenium commands (Selenese) together is understood as test script.

What is Selenium 2.0?

 It is the combination of Selenium RC and WebDriver.

What is Xpath?

 It is a path of element in a XML documents. By using this we can easily find out a web element on a webpage.

Syntax of Xpath is:

  //tagname[@attribute=’value’]


What is Locators in Selenium WebDriver ?
  

Locators is used to identify the unique web elements on the webpage. It is the properties of HTML web pages. There are different types of locators we are using to find the web elements like:

    ID
    Name
    cssSelector
    Link text
    PartialLinkText
    ClassName
     tagName


What is difference between Absolute path and Relative Path?

Absolute xpath start with single forward slash (/) which means you can select the element from the root node.
    Example: html/body/div[4]/div[2]/div[2]/div[2]/div[2]/div[2]/div[2]/div/div[4]/div[1]/div/div/div/div[1]/div[1]/div/div/div/h3/a


absolute xpath in selenium automation


Relative xpath start with double forward slash (//) and middle of the HTML content. It is small and robust than absolute xpath.
  
Example: .//*[@id=’Blog1′]/div[1]/div[1]/div/div/div/h3/a


relative xpath

What are the different challenges with Selenium?
    

1. Selenium only supports web-based application.

2. It can’t read the CAPTCHA code.

3. Selenium doesn’t have inbuilt facility to generate test results.

4. Since Selenium is an Open Source tool so, it doesn’t provide any technical supports.

 5. Selenium doesn’t any object repository, so we can’t maintain object in this. To overcome this we are using Page Object Model concept.

What is difference between Assert and Verify?

Assert — If we are using assert command in our test script then test execution will be stop if there is any test step failed. Test case is terminated at that point.

Verify — It is also using for verify the test steps, but at any point test steps failed, test execution will be continued. Selenium move on next line of code and testing is continue.

What is synchronization in Selenium Webdriver?

Sometimes Selenium is faster than our web application or vice versa. In this case we have to manage the speed of both to run our test scripts. So we have different wait commands for this like implicit wait, explicit wait etc.

What is difference between implicit wait and explicit wait?

Implicit wait: In this we set time for entire duration of test execution. For example if selenium is not found any element then it wait for element for given period of time. If element doesn’t found that element in given time then it will be throw an exception ElementNotVisibleException‘.

   driver.manage().timeouts().implicitlyWait(20, TimeUnits.SECONDS);

Explicit wait: In this we set time for particular one element. Where we have certain conditions like Element is Visible, Button is clickable etc. For example if we set explicit wait for 20 seconds for a button then selenium wait for 20 seconds for that button. If button will not be clickable in 20 seconds then selenium throw a exception ‘ElementNotVisibleException’.

   WebDriverWait wait = new WebDriverWait(driver, 10);

   wait.until(ExpectedConditions.elementToBeClickable(By.id(“id”)));


What is iframe and how to handle it with Selenium?

Iframe is a web page which is separate part of HTML pages. Iframe use for to show some different things like Advertisment etc. For iframe we uses <iframe> tag.

How to handle iframe: Before handle the iframe first we should know the how to identify the iframe in any web page. So first you need to search the iframe in html of the web page like below image.

You can see iframe tag in the image.
Now in selenium iframe can be handle in three different ways:
      1. By Name

        driver.switchTo().frame(“frameName”);

      2. By Index

        driver.switchTo().frame(indexOfFrame);
      3. By WebElement

       driver.switchTo().frame(“xpath of frame “);

Iframe Selenium Automation Interview Questions


What are the different types of drivers in WebDriver ?
      

FirefoxDriver
      ChromeDriver
      InternetExplorerDriver
      SafariDriver
      OperaDriver
      AndriodDriver
      IPhoneDriver
      HtmlUnitDriver
    

How to check any checkbox is selected or not?

By using isSelected() method.
    
      driver.findElement(By.xpath(“locator of Checkbox”)).isSelected();



How to check any button is enabled or not?
    

By using isEnabled() method.

      driver.findElement(By.xpath(“locator of  button”)).isEnabled();



How to check any web element is visible or not?


By using isDisplayed() method.

        driver.findElement(By.xpath(“locator of  web element”)).isDisplayed();

How to get a text from a textbox?

By using getText() method.

      driver.findElement(By.xpath(“xpath of textbox”)).getText();


What is Actions class?

Actions class is used to handle the keyboard events, mouse hover events (such a Drag and Drop, Press Enter, Tab, Shift key etc.). We can also double click on any element, Right click on any element using Action class.

    Example:
    
     Actions act=new Actions(driver);
    // mouse hover on an element and click on it.
     act.moveToElement(element).click().build().perform();

   Note: build method is use to close all series of actions and perform method is to use to perform all actions at a time.
  

How to select a value from dropdown?

By using Select class we can do this. Select class having different methods to select the dropdown value.

selectByIndex()

selectByValue()

selectByVisibleText()          

     Example:

     WebElement element= driver.findElement(By.xpath(“xpath of city dropdown”));

  

      Select dropdownvalue = new Select(element);
      dropdownvalue.selectByIndex(1); // It will select the 2nd drop down value- Jaipur
      dropdownvalue.selectByValue(“Jaipur”);
      dropdownvalue.selectByVisibleText(“Jaipur”);

What is difference between get() and navigate() ?


Get(): When we used get command the page will wait until the whole page gets loaded.

                   driver.get(“URL of the site”);
      

Navigate(): When we used navigate command then selenium just navigate the page to the given url.
                  driver.navigate().To(“URL”);

      Navigate is also used for move forward, back direction and refresh the page
                
                driver.navigate().forward();
                driver.navigate().back();
                driver.navigate().refresh();


How to handle the web based popup with Selenium?

By using Alert interface we are handle web based popup. It has different methods like accept(), dismiss() etc. So first we need to switch on alert popup then perform any action.

            driver.switchTo().alert().aceept(); // To click on OK button on alert.

            driver.switchTo().alert().dismiss(); // To click on cancel button on alert

            String alerttext=driver.switchTo().alert().getText();

How to get page title of the web application?

String pagetitle = driver.getTitle();



get page title

How to handle multiple windows in Selenium?

Sometime when we click on any link then a window is opened and in our test case we have to perform some action on that opened window (called as child window) so first we need to switch on this child window then we can perform any action. Below code handle the multiple window.

        String parent_win = driver.getWindowHandle(); //store parent window in a string

        Now assume after click on any link a child window will be open.

        Set<String> child_win = driver.getWindowHandles(); // store all child windows in a string using Set interface.

       for (String child_Windows : child_win )
             {
             driver.switchTo().window(child_Windows); // switch to child window
             }
        


How to verify tooltip text in Selenium?

To verify the tooltip text first we have to mouse over on that element on which tooltip is coming then read the tooltip by using getAttribute() method.

In above image we will read tooltip of Gallery menu.

    // First we mouse hover on Gallery

      WebElement element = driver.findElement(By.xpath(“xpath of Gallery”));
      Action act = new Actions(driver);
      act.moveToElement(element).build().perform();

   // Read tooltip and store in a string
  
      String tooltip_text = element.getAttribute(“title”); // In title we can found tooltip text i.e see in image html section.

  // Use assert command to verify the tooltip text

      Assert.assertEquals(“visitor gallery”, tooltip_text);


What are the different exceptions we are facing in Selenium WebDriver?


 NoSuchElementException
 NoSuchWindowException
 ElementNotVisibleException
 TimeOutException
 StaleElementReferenceException
 UnReachableBrowserException


How to upload the file using Selenium?

By using sendKeys() command we can upload it. In sendKeys we will pass the location of file, which we want to upload.
But Sometime when we click on upload file button then window popup is opened to select the file from the Pc. In this case sendKeys command is not working so we will use AutoIt, Robot third party tool to upload the file.


How to perform the right click with Selenium?

By using Actions class and conextClick() command we can right click.
    
      WebElement element = driver.findElement(By.xpath(“locator of element”));
      Actions act = new Actions(driver);
      act.moveToElement(element).perform();
      act.contextClick().perform();





                 

Leave a Comment