Python Windows身份验证用户名和密码不起作用 [英] Python Windows Authentication username and password is not working

查看:184
本文介绍了Python Windows身份验证用户名和密码不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在提示符(给出的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.0 geckodriver v0.18.0 Mozilla Firefox 53.0 通过 Python 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")

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()

I have tried with:

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

This one is also not working.

解决方案

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.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆