html例子:点击链接,代开51网站
<html>
<head><title>Test Popup Window</title></head>
<body>
<a id = "51" href = "http://www.51.com/" target = "_blank">Let's go!</a>
</body>
</html>
代码实现:
package web;
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class PopUp {
public static void main (String [] args) throws InterruptedException{
WebDriver dr;
System.setProperty ( "webdriver.firefox.bin" , "D:/Program Files/Mozilla Firefox/firefox.exe" );
dr = new FirefoxDriver();
String url = "file:///D:/test.html";
dr.get(url);
Thread.sleep(3000);
dr.findElement(By.id("51")