Top 20 Advanced Selenium Webdriver Coding Interview Questions of 2019


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
      js.executeScript("javascript:window.scrollBy(0,350)");
    
      // Horizontal Scroll
      js.executeScript("javascript:window.scrollBy(250,0)");



    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
     r.keyPress(KeyEvent.VK_ALT);
     r.keyPress(KeyEvent.VK_S);
     
     // Now, release S and Alt key
     r.keyRelease(KeyEvent.VK_S);
     r.keyRelease(KeyEvent.VK_ALT);
     
     // Press Enter Key as Focus is on Save button, so it will be 
     r.keyPress(KeyEvent.VK_ENTER);
     
     // Release Enter key
     r.keyRelease(KeyEvent.VK_ENTER);
    
    
    
    
    
    
    
    


    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
     driver.switchTo().window(window2);
    
    
    Case 2 :
     /* Moving Between all Windows
      */
     for (String handle : driver.getWindowHandles()) {
      driver.switchTo().window(handle);
     }
    
    
    
    
    
    
    
    

    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?





    Comments

    Popular Posts

    Top 10 Demo Websites to Practice Selenium Webdriver Online

    Top 25 Must to know Selenium Webdriver Commands List

    Selenium-TestNG Integration Explained with Coding Example

    Selenium Essentials - How to become expert in Automation Testing?