如何使用Selenium WebDriver使用HtmlUnitDriver处理身份验证? [英] How do I handle authentication with the HtmlUnitDriver using Selenium WebDriver?

查看:311
本文介绍了如何使用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;
    }
};

这篇关于如何使用Selenium WebDriver使用HtmlUnitDriver处理身份验证?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆