我正在尝试使用 PyCharm 上的 Python/Selenium 从 Edge 获取 INFO 级别的浏览器控制台日志事件,但当前配置仅从浏览器返回 WARNING 级别的日志。我有意使用 msedge.selenium_tools 库,因为 Edge 上的 webdriver 库似乎已被弃用。
import time
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
capabilities = DesiredCapabilities.EDGE
capabilities['loggingPrefs'] = {'browser': 'ALL'}
capabilities['acceptInsecureCerts'] = bool(True)
edge_options = EdgeOptions()
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
edge_options.use_chromium = True
driver = Edge(options=edge_options, desired_capabilities=capabilities, executable_path=r"C:\\Users\\myuser\\Documents\\edgedriver_win64\\msedgedriver.exe")
...
输出:
[{'level': 'WARNING', 'message': 'Message I'm getting'}]