【发布时间】:2021-03-17 01:31:56
【问题描述】:
我正在学习使用 Selenium 学习 Python 3.7 的第二天。
我正在使用 WebDriver 访问网页。我一直在进步,但现在受到了阻碍。虽然我可以在我的普通浏览器(选项/隐私和安全/位置/设置)上轻松禁用 Firefox 密码管理器弹出窗口,但我的脚本的远程运行(认为这是根据定义)浏览器无法识别该配置,并且 Firefox 弹出窗口出现了。
脚本可以忽略弹出窗口并导航目标站点,直到我需要访问的最后一页。那时,该页面的 HTML 无法访问,直到我手动单击 Firefox 弹出窗口,将其关闭。一旦我这样做了,该网页的 HTML 代码就会在 Firefox Web Developer Inspector 中亮起。
现在,HTML 代码可能由于其他原因无法访问(就像我说的,学习曲线的第 2 天),但是 Webdriver 中是否有一些库或命令允许我自动关闭该 FireFox 弹出窗口。它不是任何页面的 HTML 的一部分,所以我很茫然。
编辑:我还要提一下,在我手动关闭 FireFox 弹出窗口之前,最后一页的大部分内容都是空白的。
我添加了以下代码,但仍然得到相同的弹出窗口:
from selenium import webdriver
#Using Firefox to access the Web
options = webdriver.FirefoxOptions()
options.set_preference("dom.webnotifications.enabled", False)
driver = webdriver.Firefox(options=options)
driver.maximize_window()
第二次编辑:这是定义配置文件的当前代码部分,我仍在弹出密码管理器。
import datetime
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
#Using Firefox to access the Web
profile = webdriver.FirefoxProfile()
#profile.set_preference("dom.push.enabled", False)
profile.set_preference("dom.webnotifications.enabled", False)
profile.update_preferences()
driver = webdriver.Firefox(firefox_profile=profile)
driver.maximize_window()
【问题讨论】:
-
您是否将 Selenium 设置为使用某个 firefox 配置文件?
-
我没有。我在另一条评论中读到 Firefox 配置文件已被弃用。如何设置个人资料?
-
我在原始帖子中添加了我的第二次编辑,其中显示了与配置文件相关的代码。我仍然看到弹出密码管理器。