Top 20 Selenium Webdriver Interview Questions of 2020

Question 1 - How to handle Alerts or Pop-Ups using Selenium Webdriver?

Answer - Alerts or javascript pop-ups can be handled by using commands of org.openqa.selenium.Alert class in Selenium Webdriver. 
Read details - Alert Handling
Answer - Multiple browser tabs can be handled using Keys enumerator and switchTo() method. 

Question 3 - How to Achieve Code Reuseablity & Maintainablility in Selenium Code?

Answer - Code re-usability can be achieved by creating page methods (action methods) and use those methods in your test method code instead of direct selenium commands.

Question 4 - How to Handle Dynamic Web Table in Selenium WebDriver?

Answer - We can handle dynamic web table by preparing dynamic xpath of table at runtime. 
Read details - Handle Dynamic Table

Question 5 - How to Extract Table Data/Read Table Data Using Selenium WebDriver?

Answer - We can extract table data by preparing dynamic xpath of table at runtime. 
Read details - Extract Table Data

Question 6 - How to Take Partial Screenshot in Selenium Webdriver?

Answer - Partial screenshot can be taken by using org.openqa.selenium.Point class of Selenium. We can get height and width of the element by using Point class. 
Read details - Take Partial Screenshot

    Question 7 - How to take screenshot in Selenium Webdriver?

    Answer - Screenshot can be taken by using org.openqa.selenium.TakesScreenshot class of Selenium.

    Question 8 - What is Actions class? What are its commands?

    Answer - Actions class is used to handle Keyboard and Mouse Events. You need to import org.openqa.selenium.interactions.Actions in order to use Actions class.

    Question 9 - How to upload a file in Selenium Webdriver?

    Answer - Selenium can't directly interact with window dialogues but we can interact with them by keyboard interactions using Selenium's Keys class or Java's Robot class.

    Question 10 - How to do Mouse hover in Selenium Webdriver?

    Question 11 - What is TestNG? How it can be integrated with Selenium?

    Question 12 - How to create setup and teardown methods in TestNG?

    Question 13 - What is the difference b/w @BeforeClass, @BeforeMethod and @AfterClass, @AfterMethod in TestNG?

    Question 14 How to set priority of test methods in TestNG?

    Question 15 - How to scroll vertically and horizontally using Selenium Webdriver?

    Answer - Scroll can be done in selenium using org.openqa.selenium.JavascriptExecutor

    Example - 

       // Create object of JavascriptExecutor
      JavascriptExecutor js = (JavascriptExecutor) driver;
      // Vertical Scroll
      // Horizontal Scroll

    Question 16 How to download file using Selenium Webdriver?

    Answer - You can download a file using Robot class.

    Example -

      /* Download file by clicking on Save button of window dialog

     // Create object of Robot class
     Robot r = new Robot();  
     // Press Alt and S key, it will shift the focus to 'Save' button of Windows dialog
     // Now, release S and Alt key
     // Press Enter Key as Focus is on Save button, so it will be 
     // Release Enter key

    Question 17 How to switch to Nth browser window in Selenium Webdriver?

    Answer - Code example -

    Case 1:

     // Create a Set and store all window handle ids in it
     Set AllWindowHandles = driver.getWindowHandles();
     String window1 = (String) AllWindowHandles.toArray()[0];
     String window2 = (String) AllWindowHandles.toArray()[1];
     // Switch to window with id 2
    Case 2 :
     /* Moving Between all Windows
     for (String handle : driver.getWindowHandles()) {

    Question  18 - How to handle ajax elements using Selenium Webdriver?

    Answer - When we do Google search and a list of options matching to our keyword displayed on it's own without refreshing the page, is an example of ajax search. We can handle ajax elements using Explicit Wait in Selenium.

    Question  19 - How to switch frames in Selenium Webdriver?

    Answer - Code example -

      // Move to frame
     driver.switchTo().frame("Target Web element")


    Question  20 - How to find broken links of a web page using Selenium Webdriver?

    Follow Us

    Quora Space | Facebook Page | Telegram Channel
    Feel free to ask queries or share your thoughts in comments or email us.


    Popular posts from this blog

    10 Best Demo Websites for Automation Testing Practice

    Automate E-Commerce Website using Selenium Webdriver

    Automate Browser Actions on using Selenium

    Automate Amazon Website 'Menu links' using Selenium