我正在使用 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/