0
votes

When I click on Help Screen in a web page, it opens a new web browser window containing information of of help webpage. I wanted to read some text or title of that webpage, but i can't able to read anything of that help window. The main objective in this case is to verify the help screen content and close that help window after verifying the help screen. The code i'm using is as follows:

public void verifyNewWindow(String buttonId, String screenShotFileName) {

    String winHandleBefore = driver.getWindowHandle();
    clickOnButton(buttonId); //Clicking on help button on a webpage, help id is passed from baseclass)
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    for(String winHandle : driver.getWindowHandles()){
        if(!winHandle.equals(winHandleBefore))
        {
            driver.switchTo().window(winHandle);
            takeScreenShot(screenShotFileName);
            driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
            driver.close();
            break;

        }
    }
           driver.switchTo().window(winHandleBefore);
}
1
The new window which opens is it a html page? Usually help section will be pdf.Vinay
@Vinay: Hi Vinay. Thanx for replying. The new window opens is an html webpage, not pdf.Sangamesh_R

1 Answers

0
votes

First get the window handles(not handle) after opening the new window.

Set<String> windows = driver.getWindowHandles();

Once you get the window handles then iterate through them and get the child window handle as below;

String parent = null;
String child = null;
Iterator it = windows.iterator();
while(it.hasNext())
{
  parent = it.next();
  child = it.next();
}

Then switch to the child window.

driver.switchTo().window(child);