chromedriver use

1. Call chrome driver

System.setProperty("webdriver.chrome.driver", "C:/Program Files (x86)/Google/Chrome/Application/chromedriver.exe");

2. Create chromeOption objects

ChromeOptions chromeOptions = new ChromeOptions();

3. The property is set

FIG disposed No 3.1:

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.managed_default_content_settings.images", 2);
chromeOptions.setExperimentalOption("prefs",prefs);

 

Free detector provided 3.2 (Developer Mode)

List excludeSwitches=new ArrayList<String>();
excludeSwitches.add("enable-automation");
chromeOptions.setExperimentalOption("excludeSwitches",excludeSwitches);

 

3.3 ip proxy settings

String ip = "122.236.112.128:4267";
chromeOptions.addArguments("--proxy-server=http://" + ip);

 

3.4 Setting browser size

Driver = the WebDriver new new ChromeDriver (chromeOptions);
 // resizing the browser 
driver.manage () window () the setSize (.. New new the Dimension (1300, 800 )); 
((ChromeDriver) Driver) .get (URL);

 

3.5 Set Cookie

Cookie cookie = new Cookie("name","value");
driver.manage().addCookie(cookie);

 

3.6 Setting headless

chromeOptions.addArguments("-headless");

 

Guess you like

Origin www.cnblogs.com/ushowtime/p/11619333.html