使用 Selenium 处理浏览器身份验证 [英] Handling Browser Authentication using Selenium
问题描述
有谁知道在自动化过程中使用 Selenium 或任何其他工具处理浏览器身份验证?
Does anyone know about handling Browser Authentication using Selenium or any other tool during automation?
推荐答案
EDIT in 2015:
这个答案已经过时了.WebDriver 现在支持身份验证!请参阅如何使用 Java 处理 Selenium WebDriver 的身份验证弹出窗口
Selenium 处理得不是很好.
This is not handled very well by Selenium.
您可以尝试使用 http://username:password@example.com/yourpage
而不仅仅是http://example.com/yourpage
但是,据我所知,Firefox 仍然会弹出一个浏览器对话框要求确认.
However, as far as I know, Firefox will still pop up a browser dialog requesting a confirmation.
您可以尝试 Robot 如果您正在使用 Java(或任何类似的工具,如 AutoIt).
You can try Robot if you're using Java (or any similar tool like AutoIt).
您可以使用 driver.manage().addCookie()
如果您使用的是 WebDriver.
You could use driver.manage().addCookie()
if you're using WebDriver.
或自定义 FirefoxProfile 已经通过一次认证.
Or a custom FirefoxProfile that has already passed the authentication once.
这篇关于使用 Selenium 处理浏览器身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!