Python Windows 身份验证用户名和密码不起作用 [英] Python Windows Authentication username and password is not working
问题描述
我试图在提示中输入数据(给出的 URL),下面的代码给了我一个错误.请帮我解决这些问题?
I am trying to enter data in prompt (URL Given), below codes is giving me an error. Please help me out with these?
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
你可以绕过Basic Authentication
通过将 username
和 password
嵌入到 url
本身中而弹出,如下所示.
When you work with Selenium 3.4.0
, geckodriver v0.18.0
, Mozilla Firefox 53.0
through Python 3.6.1
you can bypass the Basic Authentication
popup through embedding the username
and password
in the url
itself as follows.
此解决方案打开 URL
http://the-internet.herokuapp.com/basic_auth 并使用有效的username
和password
凭据进行身份验证.
This solution opens the URL
http://the-internet.herokuapp.com/basic_auth and authenticates with a valid username
and password
credentials.
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")
这篇关于Python Windows 身份验证用户名和密码不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!