IE中的Selenium Webdriver和Basic Auth [英] Selenium Webdriver and Basic Auth in IE
本文介绍了IE中的Selenium Webdriver和Basic Auth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用Selenium Webdriver为IE中的基本身份验证对话框提供用户名和密码?传递URL中的凭据不是我们的选择。
Is there any way to provide username and password to a basic auth dialog in IE using Selenium Webdriver? Passing the credentials in the URL is not an option for us.
推荐答案
我得到了这个史诗问题的解决方案
I got a solution for this epic problem
使用awt !!
打开URL并使用下面给出的java Robot类或SmartRobot类:
Open the URL and use the java Robot class or the SmartRobot class given below:
class SmartRobot extends Robot {
public SmartRobot() throws AWTException
{
super();
}
/*public void pressEnter()
{
keyPress(KeyEvent.VK_ENTER);
delay(50);
keyRelease(KeyEvent.VK_ENTER);
} */
public void pasteClipboard()
{
keyPress(KeyEvent.VK_CONTROL);
keyPress(KeyEvent.VK_V);
delay(50);
keyRelease(KeyEvent.VK_V);
keyRelease(KeyEvent.VK_CONTROL);
}
public void type(String text)
{
writeToClipboard(text);
pasteClipboard();
}
private void writeToClipboard(String s)
{
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
Transferable transferable = new StringSelection(s);
clipboard.setContents(transferable, null);
}
}
并使用此类类似.... / p>
and use this class something like....
try{
SmartRobot robot = new SmartRobot();
robot.type(username);
robot.keyPress(KeyEvent.VK_TAB);
robot.type(password);
robot.keyPress(KeyEvent.VK_ENTER);
}catch(Exception AWTException){
System.out.println("Exception " + AWTException.getMessage());
}
解决方案就像一个魅力,不需要任何第三方工具,如AutoIt或Sikuli。
The solution works like a charm, without needing any 3rd party tools like AutoIt or Sikuli.
这篇关于IE中的Selenium Webdriver和Basic Auth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文