我嘗試使用特定主頁設置啓動Chrome。下面給出的代碼,我使用:使用Selenium-Java啓動具有特定主頁的Chrome
package WebDriverInitialization;
import java.util.HashMap;
import java.util.Map;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
public class LaunchChrome {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","D:\\Technology Lab\\+ProgramFiles\\selenium-drivers\\chromedriver.exe");
Map<String, Object> hmPrefs = new HashMap<String, Object>();
hmPrefs.put("browser.startup.page", 1);
hmPrefs.put("browser.startup.homepage", "http://www.seleniumhq.org");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setExperimentalOption("prefs", hmPrefs);
DesiredCapabilities chromeCaps = DesiredCapabilities.chrome();
chromeCaps.setCapability(ChromeOptions.CAPABILITY, chromeOptions);
WebDriver chromeDriver = new ChromeDriver(chromeCaps);
chromeDriver.manage().window().maximize();
}
}
當我運行它,我得到一個空白頁「的數據:」,在URL中 - 例如Chrome瀏覽器如何啓動默認。代碼的最後一行被執行並且頁面被最大化。
我使用硒版本3.0.1
; java版本1.8.0_92
; Chrome版本56.0.2924.87
和ChromeDriver版本2.27.440174
的Windows 7 Professional SP1 x64
。
任何人都可以指出上述代碼中的錯誤,並讓它以http://www.seleniumhq.org
作爲主頁啓動Chrome嗎?
謝謝!
我沒有看到任何呼叫導航到特定頁面。你有沒有試過chromedriver.navigate.to()? –
我的目標是使用特定主頁啓動Chrome,而無需導航到網址。 – John
你有沒有試過'chromeCaps .setCapability(「chrome.switches」, Arrays.asList(「--homepage = http://www.seleniumhq.org」));' –