HtmlUnitDriver:启用/禁用基本身份验证?

时间:2015-11-13 10:28:43

标签: java selenium basic-authentication http-basic-authentication htmlunit-driver

this question的答案显示了如何使用HtmlUnitDriver启用基本身份验证。但是,如何再次禁用它?

注意:此问题的接受答案是正确的,但due to a bug目前无效。

1 个答案:

答案 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;
    }
};