I've encountered a dilemma that I'm trying to solve. On my webpage, there's a screen that opens a dialog box for file upload. Although I managed to select the file, the dialog box refuses to close and remains open, preventing me from proceeding with other tasks on the screen. I attempted various methods like closing the driver, creating a function to find all open windows, but none of them could locate the pesky dialog box. How can I successfully close this persistent dialog box? The code snippet below showcases my unsuccessful attempt in which it recognizes only one window is open.
Thread.sleep(8000);
Set <String> w = deiver2.getWindowHandles(); // create set of all windows
deiver2.switchTo().activeElement();
System.out.println("Window title: "+ deiver2.getTitle());
deiver2.findElement(By.xpath(""//input[@type='file']"))
.sendKeys(
""X:\\AutomationFiles\\yoyoy.pdf");
for (String h: w){
deiver2.switchTo().window(h);
String s= deiver2.getTitle();
System.out.println("Window title: "+ deiver2.getTitle());
if(s.equalsIgnoreCase("Open")){
System.out.println("Window title to be closed: "+ deiver2.getTitle());
deiver2.close();
}
}
deiver2.switchTo().window(base);
System.out.println("END");