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



            String windowTitle = driver.getTitle();

                System.out.println("Invoice PDF failed to open");
                System.out.println("Invoice PDF open successfully.");
  • 1
    Welcome to the site. I think you need to say in your code what window you're getting the title from. This might be helpful stackoverflow.com/a/45715566/10401931 In short, your driver will be referring to the first tab, not the new one with your PDF. You need to change that.
    – pavelsaman
    Nov 25, 2019 at 11:32

1 Answer 1


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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.