Python Selenium 4.3连接Electron应用时无法获取Chromedriver性能日志
问题:ChromeDriver连接Electron应用时无法获取性能日志
尝试通过ChromeDriver获取Electron应用的性能日志以抓取全部网络数据,试过多种现有方案均无效。
初始代码
caps = DesiredCapabilities.CHROME caps["goog:loggingPrefs"] = {'performance': 'ALL'} service = Service(executable_path="./chromedriver.exe") option=Options() option.binary_location=path.abspath("./tsm-console-desktop.exe") option.add_argument("remote-debugging-port=9515") cdriver=webdriver.Chrome(service=service,options=option,desired_capabilities=caps)
后续操作
执行以下代码尝试获取日志:
# Electron应用会自动加载设定的URL cdriver.get_log('browser')
遇到的问题
所有方案都建议调用cdriver.get_log('performance'),但Python提示该参数无效。实际获取到的日志仅包含控制台信息,无性能相关内容,示例如下:
{'level': 'SEVERE', 'message': 'https://dev.local.elektaplatform.com/otel-agent/v1/traces - Failed to load resource: the server responded with a status of 404 ()', 'source': 'network', 'timestamp': 1659614239337}
解决方法
改用WebDriver构造函数中的executable_path参数而非Service类后问题解决,修正后的代码如下:
webdriver.Chrome(executable_path='./chromedriver.exe',options=option,desired_capabilities=caps)
内容的提问来源于stack exchange,提问作者Neil Ajgaonkar
相关产品推荐
相关产品推荐

