python - 如何使用 Selenium python-binding webdriver 提交 HTTP 身份验证

标签 python selenium

我正在使用 Selenium python 绑定(bind)为我们的 Web 应用程序设置自动化测试。我在 Beta 服务器上测试 Web 时遇到问题,因为它需要对 Intranet 用户名和密码进行 HTTP 身份验证。

from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://somewebsite.com/")

我需要在访问 http://somewebsite.com/ 时为弹出对话框提交用户名和密码

有没有一个巧妙的方法来做到这一点?

最佳答案

我找到了这个问题的解决方案:

from selenium import webdriver

profile = webdriver.FirefoxProfile()
profile.set_preference('network.http.phishy-userpass-length', 255)
driver = webdriver.Firefox(firefox_profile=profile)
driver.get("https://username:password@somewebsite.com/")

FirefoxProfile 部分是关闭确认对话框,因为默认情况下 Firefox 会显示一个弹出对话框以防止钓鱼。

关于python - 如何使用 Selenium python-binding webdriver 提交 HTTP 身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7022116/

相关文章:

python - 使用Raspberry Pi 2 Model B上的GPIO引脚控制运行ROS的P3DX机器人

python - 配置测试和覆盖率以在设置时运行

python - Selenium:测试弹出窗口

python - 为什么 Nose 测试会在 Windows 8 上留下孤立的 PhantomJS 进程?

python - 从 subprocess.Popen 启动时 Drush 挂起

python - 带有标签列的堆叠列

python - 从 Python 打印到 Heroku 日志时出现 Unicode 错误

Python Selenium Webdriver - 在指定的一个之后抓取 div

java - Selenium - webDriver 不稳定错误堆栈跟踪

python-3.x - 如何使用 XPATH 获取文本