Java selenium lesson 3 driver loading method

How to load the driver normally

System.setProperty("webdriver.chrome.driver",  "E:/googledriver/chromedriver.exe");
WebDriver driver = new ChromeDriver();

The way to load the driver after the requirement changes

1. Adjust the size of the page after loading the driver

2. Hide the browser window

3. It is forbidden to load pictures

 //chromedriver服务地址
System.setProperty("webdriver.chrome.driver", "D:/selenium/chromedriver.exe");
ChromeOptions chromeOptions = new ChromeOptions();
//无头
chromeOptions.addArguments("--headless"); 
//窗口大小
chromeOptions.addArguments("--window-size=1920,1080");
//禁止加载图片
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.managed_default_content_settings.images", 2);

chromeOptions.setExperimentalOption("prefs", prefs);
//加载配置
WebDriver driver = new ChromeDriver(chromeOptions);

Prohibiting the loading of pictures and hiding the browser window will cause some page js to fail to load, resulting in invalid clicks.

Guess you like

Origin blog.csdn.net/weixin_41160534/article/details/102912454