弄了很久,也只能做到单个页面的随机点击,做整个网站的随机点击只能交给以后的自己
需要添加selenui-standalone.jar,jsoup.jar
@Test
public void testrandom() throws IOException, InterruptedException{
WebDriver driver=new FirefoxDriver();
driver.get("http://192.168.2.252/index/");
Thread.sleep(3000);
Document doc = Jsoup.connect("http://192.168.2.252/index/").get();
Element body = doc.body();
Elements es=body.select("a");
int size=es.size();
// for (Iterator it = es.iterator(); it.hasNext();) {
// Element e = (Element) it.next();
// System.out.println(e.text()+" "+e.attr("href"));
// }
Random random =new Random();
for(int i=0;i<1000;i++){
int r=random.nextInt(size);
Element link = doc.select("a").get(r);
String relHref = link.attr("href"); // == "/"
String absHref = link.attr("abs:href"); // "http://www.open-open.com/"
driver.get(absHref);
}
}