簡體   English   中英

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.0Python 3.6.1您可以通過將usernamepassword嵌入url本身來繞過Basic Authentication彈出窗口,如下所示。

此解決方案打開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)

上面的代碼也正常工作:)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM