Python的Windows身份验证用户名和密码不起作用
问题描述:
我想在提示中输入数据(URL给出),下面的代码给我一个错误。请帮我解决这些问题?Python的Windows身份验证用户名和密码不起作用
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.0
工作,geckodriver v0.18.0
,Mozilla Firefox 53.0
通过Python 3.6.1
您可以通过自身嵌入username
和password
在url
如下绕过Basic Authentication
弹出。
该解决方案将打开URL
http://the-internet.herokuapp.com/basic_auth并且以有效username
和password
证书认证。
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:[email protected]/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)
上面的代码也工作正常:)
不知道这是你的问题,但我看到的第一件事情是你忘了“()”在戒备= driver.switch_to.alert () – Chai
尝试:'警报= driver.switch_to.alert() TypeError:'警报'对象不可调用 – jaibalaji