以下是我的代码,无法使用Selenium最大化chrome窗口。
System.setProperty("webdriver.chrome.driver",CONFIG.getProperty("driverPath")+"chromedriver.exe");
String downloadFilepath = filePath;
HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
chromePrefs.put("profile.default_content_settings.popups",0);
//1-Allow, 2-Block, 0-default
chromePrefs.put("profile.default_content_setting_values.notifications", 0);
chromePrefs.put("download.default_directory", downloadFilepath);
chromePrefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player", 1);
chromePrefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);
chromePrefs.put("PluginsAllowedForUrls", CONFIG.getProperty("websiteUrl"));
ChromeOptions options = new ChromeOptions();
HashMap<String, Object> chromeOptionsMap = new HashMap<String, Object>()
options.setExperimentalOption("prefs", chromePrefs);
options.addArguments("disable-popup-blocking");
options.addArguments("--disable-notifications");
options.addArguments("disable-infobars");
options.addArguments("--disable-web-security");
options.addArguments("--allow-running-insecure-content");
options.addArguments("--test-type");
options.addArguments("--start-maximized"); DesiredCapabilities cap = DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
cap.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
cap.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(cap);
请查看附件
萧十郎
郎朗坤
相关分类