String Currentwindow = Driver.getwindowhandle ();//Gets the current window handle
Set<string> handles = Driver.getwindowhandles ();//Get all window handles
Iterator<string> it = Handles.iterator ();
while (It.hasnext ()) {
if (Currentwindow = = It.next ()) {
Continue
}
Webdriver window = Driver.switchto (). Window (It.next ());//Switch to new windows
if (Window.gettitle (). Equals (Constant.jd_login_title)) {
Webelement loginname = window.findelement (By.name ("LoginName"));
Loginname.click ();
Loginname.sendkeys (User.getname ());
Webelement nloginpwd = window.findelement (By.name ("nloginpwd"));
Nloginpwd.click ();
Nloginpwd.sendkeys (User.getpwd ());
by classname Usage
Window.findelement (By.id ("Loginsubmit")). Click ();
}
Window.close ();//Close New window
}
Driver.switchto (). window (Currentwindow);//Return to the original page
Switch to a new browser window with a link open