如何使用Selenium WebDriver使用HtmlUnitDriver处理身份验证?
问题描述:
如何使用HtmlUnitDriver处理身份验证?
How do I handle authentication with the HtmlUnitDriver?
答
在Java中尝试一下似乎对我有用
Try this in java seemed to work for me
WebDriver driver = new HtmlUnitDriver() {
protected WebClient modifyWebClient(WebClient client) {
// This class ships with HtmlUnit itself
DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
// Set some example credentials
creds.addCredentials("username", "password");
// And now add the provider to the webClient instance
client.setCredentialsProvider(creds);
return client;
}
};