首页 > 其他 > 详细

chromedriver的使用

时间:2019-10-03 11:26:49      阅读:206      评论:0      收藏:0      [点我收藏+]

1.调用chrome driver

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

2.创建chromeOption对象

ChromeOptions chromeOptions = new ChromeOptions();

3.属性设置

3.1无图设置:

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

 

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

List excludeSwitches=new ArrayList<String>();
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(new Dimension(1300, 800));
((ChromeDriver) driver).get(url);

 

3.5设置Cookie

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

 

3.6设置无头

chromeOptions.addArguments("-headless");

 

chromedriver的使用

原文:https://www.cnblogs.com/ushowtime/p/11619333.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!