我正在尝试在启动硒铬时禁用所有镀铬扩展.但是每次运行代码时,所有扩展都会继续启动.有没有办法禁用扩展.
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver", "C:\\Selenium\\chromedriver.exe");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.binary", "C:\\Users\\ngzhongqin\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
WebDriver driver = new ChromeDriver(capabilities);
driver.get("http://www.cnn.com");
WebElement searchBox = driver.findElement(By.name("q"));
}
Run Code Online (Sandbox Code Playgroud) 我无法让 Selenium 和 Chrome (Canary) 下载文件。我正在使用 Java 和 Chrome 59/60(因为我的测试适用于 Windows 和 Linux),并且我正在尝试开始从网页下载文件。
当我从 selenium 中不设置无头模式时,chrome 窗口将打开并下载文件。
当我设置标志时--headless,chrome 窗口不会打开,下载也不会开始。
public static void chromeDownload() throws IOException, InterruptedException{
ChromeOptions options = new ChromeOptions();
String downloadFilepath = "";
if (ValidateOS.isWindows()){
System.out.println("This is a Windows system.");
System.setProperty("webdriver.chrome.driver", "resources\\driver\\chromedriver.exe");
options.setBinary("C:\\Users\\Juri\\AppData\\Local\\Google\\Chrome SxS\\Application\\chrome.exe");
downloadFilepath = "C:\\";
} else if (ValidateOS.isUnix()){
System.out.println("This is a Unix system.");
System.setProperty("webdriver.chrome.driver", "resources/driver/chromedriver");
options.setBinary("/usr/bin/google-chrome");
downloadFilepath = "/home/juri/";
}
// Manage the download
HashMap<String, Object> chromePrefs = new HashMap<>();
chromePrefs.put("profile.default_content_settings.popups", 0);
chromePrefs.put("download.default_directory", …Run Code Online (Sandbox Code Playgroud) 我在浏览一个网站时遇到的情况是,当我点击一个按钮时,它应该下载 pdf....
我正在使用最新版本的 chrome 60、selenium 3.4、chromedriver。
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("plugins.plugins_disabled", new String[] {"Chrome PDF Viewer"});
chromePrefs.put("profile.default_content_settings.popups", 0);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", chromePrefs);
DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(cap);
Run Code Online (Sandbox Code Playgroud)
我也使用了上面的代码,但它不起作用。
selenium google-chrome webdriver selenium-chromedriver chrome-options