小编典典

如何使用Selenium WebDriver使用HtmlUnitDriver处理身份验证?

selenium

如何使用HtmlUnitDriver处理身份验证?


阅读 553

收藏
2020-06-26

共1个答案

小编典典

在Java中尝试这个似乎对我有用

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;
    }
};
2020-06-26