Webdriver - HTTP身份验证对话框 [英] Webdriver - HTTP authentication dialog

查看:205
本文介绍了Webdriver - HTTP身份验证对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个非常简单的selenium-webdriver脚本。我想使用webdriver进行HTTP身份验证。

I have a very simple selenium-webdriver script. I would like to do HTTP authentication using webdriver.

脚本:

WebDriver driver = new FirefoxDriver();  
driver.get("http://www.httpwatch.com/httpgallery/authentication/");
driver.findElement(By.id("displayImage")).click();
Thread.sleep(2000);
driver.switchTo().alert().sendKeys("httpwatch");

问题:

driver.switchTo().alert().sendKeys("httpwatch");

抛出

org.openqa.selenium .NoAlertPresentException:没有警报

org.openqa.selenium.NoAlertPresentException: No alert is present

问题:


  • Webdriver是否仅查找警报对话框作为警报?

  • 我可以选择自动执行此操作而不使用AutoIt或http://用户名:密码@somesite

编辑

警报有以下方法,似乎尚未实施。

Alert has below method and does not seem to have been implemented yet.

driver.switchTo().alert().authenticateUsing(new UsernameAndPassword("username","password"))


推荐答案

问题是这不是javascript弹出窗口因此你无法操纵它通过selenium的 alert()

The problem is that this is not a javascript popup hence you cannot manipulate it via selenium's alert().

如果AutoIt和提交URL中的凭据(最简单的选项 - 只需打开) 网址并点击显示图片)不适合您,另一种方法可以是使用 AutoAuth firefox addon 来实现自动化提交以前保存的凭据:

If both AutoIt and submitting credentials in the URL (the easiest option - just open up the url and click "Display Image") are not options for you, another approach could be to use AutoAuth firefox addon to automatically submit the previously saved credentials:


当您选择
以使浏览器保存您的时,AutoAuth会自动提交HTTP身份验证对话框登录信息。 (如果你已经告诉浏览器你的用户名和密码是
,而你已经告诉它记住用户名和密码的
,为什么不只是
让它自动提交它每次问你?)

AutoAuth automatically submits HTTP authentication dialogs when you’ve chosen to have the browser save your login information. (If you’ve already told the browser what your username and password are, and you’ve told it to remember that username and password, why not just have it automatically submit it instead of asking you each time?)

按照通过Firefox中的URL进行HTTP基本身份验证不起作用?主题:



  • 安装AutoAuth Firefox插件;

  • 访问需要身份验证的网站。输入您的用户名和密码,并确保选择保存凭据;

  • 将AutoAuth安装文件保存到您的硬盘上:在插件页面,右键单击添加到Firefox和将链接保存为;

  • 将Firefox webdriver实例化如下:

  • Install AutoAuth Firefox plugin;
  • Visit the site where the authentication is needed. Enter your username and password and make sure to choose to save the credentials;
  • Save AutoAuth installation file at your hard drive: at the plugin page, right click at "Add to Firefox" and "Save link as";
  • Instantiate Firefox webdriver as following:



FirefoxProfile firefoxProfile = new ProfilesIni().getProfile("default");
File pluginAutoAuth = new File("src/test/resources/autoauth-2.1-fx+fn.xpi");
firefoxProfile.addExtension(pluginAutoAuth);
driver = new FirefoxDriver(firefoxProfile);






此外,以类似于AutoIt选项的方式 - 您可以使用 sikuli 屏幕识别和自动化工具在弹出窗口中提交凭据。


Also, in a way similar to AutoIt option - you can use sikuli screen recognition and automation tool to submit the credentials in the popup.

另请参阅其他想法和选项:

Also see other ideas and options:

  • Support BASIC and Digest HTTP authentication
  • Handling browser level authentication using Selenium

这篇关于Webdriver - HTTP身份验证对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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