how to get the window title name when its open in new window with document file



  • Scenario: after click on PDF buttton > new window open with document.

    Issue: when i used getTitle , its returned the previous page title

    Question : is it because the PDF page opens its not normal page and PDF page?

    Please help me out here

    Code:

    invoicePDFButton.click();
            Thread.sleep(7000);
    
                String windowTitle = driver.getTitle();
                System.out.println(windowTitle);
    
                if(!windowTitle.equals("servlet.FileDownload"))
                {
                    System.out.println("Invoice PDF failed to open");
                    Assert.fail();
                }
                else
                {
                    System.out.println("Invoice PDF open successfully.");
                }
    


  • Use switchTo() window

    Use switch window to switch to the window you want, then perform the test on that window.

    Windows and Tabs are used interchangeably.

    Example from above site of using an iterator to switch window:

    driver.findElement(By.id(“id of the link which opens new window”)).click();\ 
    waitForNumberofWindowsToEqual(2);//this method is for wait
    Set handles = driver.getWindowHandles();
    firstWinHandle = driver.getWindowHandle(); handles.remove(firstWinHandle);
    String winHandle=handles.iterator().next(); 
    if (winHandle!=firstWinHandle){
    secondWinHandle=winHandle; //Storing handle of second window handle
    driver.switchTo().window(secondWinHandle);
    

Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2