基礎知識: http://www.360doc.com/content/12/0525/16/1073512_213657192.shtml
源碼下載:https://code.google.com/p/selenium/downloads/detail?name=selenium-java-2.35.0.zip
切換到當前窗口:
public static void switchToCurrentWindow(WebDriver driver){
//get current window
String currentWindow = driver.getWindowHandle();
//get all windows
Set<String> handles = driver.getWindowHandles();
Iterator<String> it = handles.iterator();
while(it.hasNext()){
String handle = it.next();
if(currentWindow.equals(handle)) continue;
WebDriver window = driver.switchTo().window(handle);
System.out.println("windows changed,the title and url is "+window.getTitle()+","+window.getCurrentUrl());
}
}
移動鼠標:
public static void mouseToElement(WebDriver driver,String elementId){
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id(elementId))).build().perform();
}