3
如何處理HtmlUnitDriver的身份驗證?如何使用Selenium WebDriver處理HtmlUnitDriver的身份驗證?
如何處理HtmlUnitDriver的身份驗證?如何使用Selenium WebDriver處理HtmlUnitDriver的身份驗證?
試試這個在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;
}
};
如果這是你創建一個HtmlUnitDriver實例時需要你能做到這一點的基本身份驗證:(代碼是Scala,但你可以很容易地將其更改爲JAVA)
new HtmlUnitDriver() {
override def modifyWebClient(client: WebClient) = {
val creds = new DefaultCredentialsProvider()
creds.addCredentials("user-name", "user-password");
client.setCredentialsProvider(creds)
client
}
}
[this](http://code.google.com/p/selenium/issues/detail?id=34)有幫助嗎? –