我试图在提示中输入数据(给出的 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.webdrivermon.action_chains import ActionChains from selenium.webdrivermon.keys import Keys import time driver = webdriver.Firefox() url = "the-internet.herokuapp/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 the-internet.herokuapp/basic_auth 并使用有效的username 和password 凭据进行身份验证.
This solution opens the URL the-internet.herokuapp/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("admin:admin@the-internet.herokuapp/basic_auth")更多推荐
Python Windows 身份验证用户名和密码不起作用
发布评论