Import java. Io. file;
Import java. util. iterator;
Import java. util. Set;
Import org. openqa. Selenium.;
Import org. openqa. Selenium. WebDriver;
Import org. openqa. Selenium. Chrome. chromedriver;
/*
* How to get a new window
*/
Public class popupwindowtest {
Public static void main (string [] ARGs ){
WebDriver DR = new chromedriver ();
File file = new file ("learning/test.html ");
String filepath = "file: //" + file. getabsolutepath ();
System. Out. println (filepath );
Dr. Get (filepath );
Dr. findelement (by. ID ("51"). Click ();
// Obtain the current window handle
String currentwindow = dr. get1_whandle ();
Set <string> handles = dr. getwindowhandles ();
Iterator <string> it = handles. iterator ();
While (it. hasnext ()){
String TMP = it. Next ();
If (currentwindow. Equals (TMP) // currentwindow = TMP returns false string values compared with equals, string = compares the address
Continue;
WebDriver window = dr. switchto (). Window (TMP );
System. Out. println ("Title =" + window. gettitle () + ", url ="
+ Window. getcurrenturl ());
}
/*
* While (it. hasnext () {If (currentwindow = It. Next () continue;
*
* WebDriver window = dr. switchto (). Window (it. Next ());
* System. Out. println ("Title =" + window. gettitle () + ", url =" +
* Window. getcurrenturl ());}
*/
Dr. Quit ();
}
}