package javaapplication1;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class JavaApplication1 {
public static void main(String[] args) throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Aca\\desktop\\chromedriver.exe");
// Initialize driver
WebDriver driver = new ChromeDriver();
//Maximize browser window
driver.manage().window().maximize();
//Go to URL
driver.get("http://www.google.com");
//Set timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
// Open new tab – May be you are stuck here
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");
//Go to URL
driver.get("http://www.gmail.com");
//Set new tab timeout
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
}
我試圖打開一個新的標籤,離開原來標籤打開.. 我不能得到一個新的標籤打開。它保持開放URL在同一個標籤..我也嘗試使用操作。硒Java的新標籤在Chrome - 不會公開,保持在同一個選項卡打開URL`s
檢查這是否有幫助 - http://qaperspective.blogspot.in/2016/09/open-new-tab-using-Selenium-WebDriver.html – Amol
好的,謝謝,這工作:((JavascriptExecutor)驅動程序).executeScript( 「window.open( '', '_空白');」); –
很好用,它可以在所有現代瀏覽器上運行,因爲它們支持開箱即用的javascript。對於無頭瀏覽器,你可以參考這個鏈接http://stackoverflow.com/questions/814757/headless-internet-browser/814929#814929 – Amol