經過研究,我發現Control + t不適用於Chrome Webdriver。下面是一些我試過和不工作:如何使用selenium webdriver打開新的chrome選項卡?
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,"t");
driver.findElement(By.tagName("body")).sendKeys(selectLinkOpeninNewTab);
driver.get("www.facebook.com");
和
WebElement element = driver.findElement(By.linkText("Gmail"));
Actions actionOpenLinkInNewTab = new Actions(driver);
actionOpenLinkInNewTab.moveToElement(element)
.keyDown(Keys.COMMAND)
.keyDown(Keys.SHIFT)
.click(element)
.keyUp(Keys.COMMAND)
.keyUp(Keys.SHIFT)
.perform();
ArrayList tabs = new ArrayList (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1));
driver.get("http://www.yahoo.com");
driver.close();
driver.switchTo().window(tabs.get(0));
driver.get("http://www.yahoo.com");
driver.close();
和
ArrayList<String> tabs = new ArrayList<String> (driver.getWindowHandles());
driver.switchTo().window(tabs.get(1)); //switches to new tab
driver.get("https://www.facebook.com");
}
是任何你能一步解決此問題?