這個頁面點擊html/css後會彈出一個新的窗口,此時要操做新的窗口的內容,使用switchTocss
跳轉代碼html
driver.get("https://www.imooc.com"); //當前windowhandle(跳轉的) windowsHandle = driver.getWindowHandle(); WebElement login = driver.findElement(By.className("menuContent")); List<WebElement> items = login.findElements(By.className("item")); Actions actions = new Actions(driver); actions.moveToElement(items.get(1)).perform(); driver.findElement(By.linkText("HTML/CSS")).click();
跳轉後的窗口操做,要後去要操做的窗口windows
public void windowsHandle(){ Set<String> handles = driver.getWindowHandles(); for(String s:handles){ if(s.equals(windowsHandle)){ continue; } System.out.println(s); driver.switchTo().window(s); } driver.findElement(By.linkText("入門")).click(); }