Tutorials Hut

  • Selenium WebDriver

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report



  • How to Handle multiple windows using Selenium WebDriver ?

    Some time when a user clicks on a button or link within a web page , a new window is opened and the user has to switch to that window and perform a task on that or may be needed to perform tasks on all  the opened windows so in this tutorial we will learn about windows handling in selenium.

    we can automate above activity using selenium web driver .So in this tutorials we will understand how to handle multiple windows using selenium

    Below are few methods in selenium through we can handle windows multiple windows 

    driver.getWindowHandles() – 

      • This method helps to store the set of handles for all the windows opened.
      • Return Type of This method is Iterator<String>.

    driver.getWindowHandle()

      • This method helps to fetch or get the handle of the web page which is in focus. 
      • Return Type of this method is String.

    Using the scenario below , We will understand How to Handle multiple windows using the above methods.

    1. Launch the browser 
    2. Open URL: https://tutorialshut.com/demo-website-for-selenium-automation-practice/
    3. Click on Button ‘New Browser Window’ and a child windows will be opened
    4. Switch to child Window and get the Page title of Child window
    5. Close the child window and switch to Parent Window
    6. Close the parent window
    Handle multiple windows using Selenium WebDriver Example

    Code Implementation

    package com.test;
    
    import java.util.Iterator;
    
    import java.util.Set;
    
    import java.util.concurrent.TimeUnit;
    
    import org.openqa.selenium.By;
    
    import org.openqa.selenium.WebDriver;
    
    import org.openqa.selenium.chrome.ChromeDriver;
    
    public class HandleMultipleWindows {
    
    public static WebDriver driver;
    
    public static void main(String[] args) throws InterruptedException {
    
    // Create a new instance of the Chrome driver
    
    System.setProperty("webdriver.chrome.driver", "D:\\Drivers\\chromedriver.exe");
    
    driver = new ChromeDriver();
    
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    
    // Launch the URL
    
    driver.get("https://tutorialshut.com/demo-website-for-selenium-automation-practice/");
    
    // Maximize the window
    
    driver.manage().window().maximize();
    
    driver.findElement(By.xpath("//button[text()='New Browser Window']")).click();
    
    String MainWindow = driver.getWindowHandle();
    
    // To handle all new opened window.
    
    Set<String> s1 = driver.getWindowHandles();
    
    Iterator<String> i1 = s1.iterator();
    
    while (i1.hasNext()) {
    
    String ChildWindow = i1.next();
    
    if (!MainWindow.equalsIgnoreCase(ChildWindow)) {
    
    // Switching to Child window
    
    driver.switchTo().window(ChildWindow);
    
    // get the page title of Child window
    
    String childPageTitle = driver.getTitle();
    
    System.out.println("Title of Child Page is :" + childPageTitle);
    
    // Closing the Child Window.
    
    driver.close();
    
    }
    
    }
    
    // Switching to Parent window i.e Main Window.
    
    driver.switchTo().window(MainWindow);
    
    }
    
    }
    



  • Selenium WebDriver Tutorials

       Selenium Introduction
       Benefits of Selenium
       Four components of Selenium
       Difference b/w Selenium IDE, RC & WebDriver
       Selenium WebDriver Architecture
       Background when user execute selenium code
       Download and Install Java
       Download and Install Eclipse
       Download Selenium WebDriver
       Selenium WebDriver Locators
       Selenium - Launch Browser
       Selenium WebDriver Waits
       Selenium- Implicit wait
       Selenium- Explicit wait
       Selenium- Fluent wait
       Selenium- Commonly used commands
       Selenium- findElement & findElements
       Selenium- Selenium-Handling check Box
       Selenium- Handling Radio button
       Selenium- Handling drop down
       Selenium- Take Screenshot
       Selenium- Handle Web Alerts
       Selenium- Multiple Windows Handling
       Selenium- Handle iframes
       Selenium- Upload a file
       Selenium- Download a file
       Selenium- Actions Class Utilities
       Selenium- Mouse Actions
       Selenium- Keyboards Events
       Selenium- Handle mouse hover Actions
       Selenium- Drag and Drop
       Selenium- Scroll a WebPage
       Selenium- Context Click / Right Click
       Selenium- Double Click
       Selenium- Desired Capabilities
       Selenium- Assertions
       Selenium- Exceptions and Exception Handling
       Selenium- Difference b/w driver.close() & driver.quit()
       Selenium- difference b/w driver.get() & driver.navigate()
       Selenium- JavascriptExecutor
       Selenium- Read excel file using Fillo API
       Selenium- Database Testing using Selenium
       Selenium- Read & write excel file using Apache POI
       Selenium- Read and Write csv file in Selenium
       Selenium- Dynamic Web Table Handling
       Selenium- Maven Integration with Selenium
       Selenium- Set up Logging using Log4j
       Selenium-Implement Extent Report

















  • Leave a Reply

    Your email address will not be published. Required fields are marked *

    Scroll to Top