Python Windows 身份验证用户名和密码无效

Python Windows Authentication username and password is not working

我正在尝试在提示中输入数据(URL 给定),下面的代码给我一个错误。请帮我解决这些问题?

from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox()
url = "http://the-internet.herokuapp.com/basic_auth"
driver.get(url)
time.sleep(5)
alert = driver.switch_to.alert
alert.authenticate('admin','admin')
time.sleep(4)
alert.accept()

我试过:

ActionChains(driver).send_keys("admin").send_keys(Keys.TAB).send_keys("admin").perform()

这个也不行。

当您使用 Selenium 3.4.0geckodriver v0.18.0Mozilla Firefox 53.0 通过 Python 3.6.1 您可以通过嵌入 username 绕过 Basic Authentication 弹出窗口和 passwordurl 本身如下。

此解决方案打开 URL http://the-internet.herokuapp.com/basic_auth 并使用有效的 usernamepassword 凭据进行身份验证。

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary = FirefoxBinary('C:\Program Files\Mozilla Firefox\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path="C:\Utility\BrowserDrivers\geckodriver.exe")
driver.get("http://admin:admin@the-internet.herokuapp.com/basic_auth")
    def test_1_authentication(self):
        self.driver.get("https://the-internet.herokuapp.com/basic_auth")
        shell = win32com.client.Dispatch("WScript.Shell")
        shell.Sendkeys("admin")
        time.sleep(3)
        shell.Sendkeys("{TAB}")
        time.sleep(3)
        shell.Sendkeys("admin")
        time.sleep(3)
        shell.Sendkeys("{ENTER}")
        time.sleep(3)

以上代码也可以正常工作:)