selenium2 提供了一种无ui模式的driver,即htmlunitdriver。特点运行比较快.其实htmlunitdriver 是对htmlunit 的封装,这样大家就可以使用自己习惯selenium2 语法来用它。
设置HtmlUnitDriver代理及处理用户验证问题
Proxy proxy = new Proxy(); //设置代理服务器地址 proxy.setHttpProxy("代理服务器地址:端口号"); DesiredCapabilities capabilities = DesiredCapabilities.htmlUnit(); capabilities.setCapability(CapabilityType.PROXY, proxy); WebDriver driver = new HtmlUnitDriver(capabilities) { @Override protected WebClient modifyWebClient(WebClient client) { DefaultCredentialsProvider creds = new DefaultCredentialsProvider(); creds.addCredentials("用户名", "密码"); client.setCredentialsProvider(creds); return client; } }; driver.get("http://www.baidu.com"); System.out.println("[" + driver.getTitle() + "]");
转:设置HtmlUnitDriver代理及处理用户验证有关问题
时间: 2024-11-09 09:29:59