<!--[if !supportLists]-->1. <!--[endif]--><span style="white-space: normal; background-color: #ffffff;">test.html</span>
<!--[if !supportLists]-->2. <!--[endif]-->
<!--[if !supportLists]-->3. <!--[endif]-->
<!--[if !supportLists]-->4. <!--[endif]--><html>
<!--[if !supportLists]-->5. <!--[endif]-->
<!--[if !supportLists]-->6. <!--[endif]--> <head><title>Test Popup Window</title></head>
<!--[if !supportLists]-->7. <!--[endif]-->
<!--[if !supportLists]-->8. <!--[endif]--> <body>
<!--[if !supportLists]-->9. <!--[endif]-->
<!--[if !supportLists]-->10.<!--[endif]--> <a id = "51" href = "http://www.51.com/" target = "_blank">Let's go!</a>
<!--[if !supportLists]-->11.<!--[endif]-->
<!--[if !supportLists]-->12.<!--[endif]--> </body>
<!--[if !supportLists]-->13.<!--[endif]-->
<!--[if !supportLists]-->14.<!--[endif]--></html>
<!--[if !supportLists]-->1. <!--[endif]-->import java.util.Iterator;
<!--[if !supportLists]-->2. <!--[endif]-->import java.util.Set;
<!--[if !supportLists]-->3. <!--[endif]-->
<!--[if !supportLists]-->4. <!--[endif]-->import org.openqa.selenium.By;
<!--[if !supportLists]-->5. <!--[endif]-->import org.openqa.selenium.WebDriver;
<!--[if !supportLists]-->6. <!--[endif]-->import org.openqa.selenium.firefox.FirefoxDriver;
<!--[if !supportLists]-->7. <!--[endif]-->
<!--[if !supportLists]-->8. <!--[endif]-->public class PopupWindowTest {
<!--[if !supportLists]-->9. <!--[endif]-->
<!--[if !supportLists]-->10.<!--[endif]-->
<!--[if !supportLists]-->11.<!--[endif]--> /**
<!--[if !supportLists]-->12.<!--[endif]--> * @author gongjf
<!--[if !supportLists]-->13.<!--[endif]--> */
<!--[if !supportLists]-->14.<!--[endif]--> public static void main(String[] args) {
<!--[if !supportLists]-->15.<!--[endif]--> System.setProperty("webdriver.firefox.bin","D:\\Program Files\\Mozilla Firefox\\firefox.exe");
<!--[if !supportLists]-->16.<!--[endif]--> WebDriver dr = new FirefoxDriver();
<!--[if !supportLists]-->17.<!--[endif]--> String url ="\\Your\\Path\\to\\main.html";
<!--[if !supportLists]-->18.<!--[endif]--> dr.get(url);
<!--[if !supportLists]-->19.<!--[endif]--> dr.findElement(By.id("51")).click();
<!--[if !supportLists]-->20.<!--[endif]--> //得到当前窗口的句柄
<!--[if !supportLists]-->21.<!--[endif]--> String currentWindow = dr.getWindowHandle();
<!--[if !supportLists]-->22.<!--[endif]--> //得到所有窗口的句柄
<!--[if !supportLists]-->23.<!--[endif]--> Set<String> handles = dr.getWindowHandles();
<!--[if !supportLists]-->24.<!--[endif]--> Iterator<String> it = handles.iterator();
<!--[if !supportLists]-->25.<!--[endif]--> while(it.hasNext()){
<!--[if !supportLists]-->26.<!--[endif]--> String handle = it.next();
<!--[if !supportLists]-->27.<!--[endif]--> if(currentWindow.equals(handle)) continue;
<!--[if !supportLists]-->28.<!--[endif]--> WebDriver window = dr.switchTo().window(handle);
<!--[if !supportLists]-->29.<!--[endif]--> System.out.println("title,url = "+window.getTitle()+","+window.getCurrentUrl());
<!--[if !supportLists]-->30.<!--[endif]--> }
<!--[if !supportLists]-->31.<!--[endif]--> }
<!--[if !supportLists]-->