我正在尝试推出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();
}
}当我运行这个程序时,我会得到一个空白页面,其中包含'data:‘,就像Chrome默认发布的方式一样。代码的最后一行将被执行,页面将最大化。
我在使用Selenium版本3.0.1;java版本1.8.0_92;Chrome版本56.0.2924.87和ChromeDriver版本2.27.440174 on Windows 7 Professional SP1 x64。
有人能指出上述代码中的错误,并让它以http://www.seleniumhq.org作为主页启动Chrome吗?
谢谢!
发布于 2017-02-20 04:22:10
试试这个:
chromeOptions.setArguments("google-base-url=MY_URL");
指定可用于与Google对话的另一个URL。对测试有用。
https://stackoverflow.com/questions/42310588
复制相似问题