this question的答案显示了如何使用HtmlUnitDriver
启用基本身份验证。但是,如何再次禁用它?
注意:此问题的接受答案是正确的,但due to a bug目前无效。
答案 0 :(得分:2)
您可以使用.addCredentials()的变体:
WebDriver driver = new HtmlUnitDriver() {
protected WebClient modifyWebClient(WebClient client) {
DefaultCredentialsProvider creds = new DefaultCredentialsProvider();
creds.addCredentials(username, password, hostname, port, realm);
client.setCredentialsProvider(creds);
return client;
}
};