python - 如何在Python中使用selenium在弹出身份验证窗口时自动登录

标签 python selenium

这是我的代码。

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.alert import Alert
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver = webdriver.Firefox()
driver.get('url')

wait(driver, 30).until(EC.alert_is_present())

alert=driver.switch_to_alert()


alert.send_keys('user')
alert.send_keys(Keys.TAB)
alert.send_keys('pass')
alert.accept()

弹出窗口已启动,但之后没有任何变化。有任何想法吗?

最佳答案

您可以尝试使用以下url表单进行身份验证:

driver.get('https://username:<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="4838293b3b3f273a2c0838273a3c292466292c38662b2725" rel="noreferrer noopener nofollow">[email protected]</a>')

用户名密码更改为您的真实凭据。

关于python - 如何在Python中使用selenium在弹出身份验证窗口时自动登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35784861/

相关文章:

python - 如何从 index.html 中的模板返回 appengine 数据存储对象的键?

python - Django 世界中的项目和应用程序有什么区别?

javascript - 选择特定选项后显示隐藏字段

css - 如何通过 css 中的文本而不是 xpath 正确识别选择器

pandas - 使用 pandas/beautiful soup 抓取表数据(而不是慢的 Selenium?),BS 实现不起作用

带有 Selenium 的 Python "element is not attached to the page document"

python : Calculate the eucledean distances from one coordinates to a array with coordinates

python - Django中如何导入其他项目中的模型

python - 悲怆多处理不能 pickle

java - 使用 Selenium webdriver 登录 Gmail 失败。显示未找到密码元素