我正在尝试在提示(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 可以绕过 Basic Authentication 通过嵌入的弹出username和password在url自身如下。
Selenium 3.4.0
geckodriver v0.18.0
Mozilla Firefox 53.0
Python 3.6.1
Basic Authentication
username
password
url
此解决方案将打开URL http://the-internet.herokuapp.com/basic_auth 并使用有效的username和password凭据进行身份验证。
URL
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")