chrome driver基本使用与常见设置

1.调用chrome driver

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

2.创建chromeOption对象

ChromeOptions chromeOptions =newChromeOptions();

3.属性设置

3.1无图设置:

Map prefs =newHashMap();

prefs.put("profile.managed_default_content_settings.images", 2);

chromeOptions.setExperimentalOption("prefs",prefs);


3.2设置免检测(开发者模式)

List excludeSwitches=newArrayList();

excludeSwitches.add("enable-automation");

chromeOptions.setExperimentalOption("excludeSwitches",excludeSwitches);


3.3设置代理ip

String ip = "122.236.112.128:4267";

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


3.4设置浏览器大小

WebDriver driver =new ChromeDriver(chromeOptions);//调整浏览器大小driver.manage().window().setSize(newDimension(1300, 800));

((ChromeDriver) driver).get(url);


3.5设置Cookie

Cookie cookie =newCookie("name","value");

driver.manage().addCookie(cookie);


3.6设置无头

chromeOptions.addArguments("-headless");

你可能感兴趣的:(chrome driver基本使用与常见设置)