python - 带有 python 的 selenium remotewebdriver-性能日志记录?

标签 python logging selenium selenium-chromedriver remotewebdriver

我正在尝试从远程 webdriver 实例取回一些性能日志信息。我正在使用 Python Selenium 绑定(bind)。

据我所知,这是我应该能够取回的信息。认为它可能仅适用于 ChromeDriver。我目前正在使用 FireFox,但如果它获得我想要的信息,可以轻松切换。

但是,我是 Python 的新手(但正在学习!),关于 Python 的功能字典(当用于性能日志记录时)的文档似乎有点受限(或者我今天早上的 google-fu 很弱)。

我发现了以下内容:

DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable("performance", Level.INFO);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new RemoteWebDriver("http://localhost:9515", caps);

看起来应该可以满足我的需要。但它是Java。我不太确定如何将其转换为 Python。假设这是可能的。

有什么想法吗?

最佳答案

万一有人想知道,这似乎对我有用:

(假设您使用的是 selenium Remote )

url = 'http://remote instance IP:PORT/wd/hub'
descaps = {'browserName': 'chrome', 'loggingPrefs': {'performance': 'INFO'}}

driver = webdriver.Remote(command_executor=url, desired_capabilities=descaps)

driver.command_executor._commands.update({'getAvailableLogTypes': 
                        ('GET', '/session/sessionId/log/types'), 
                        {'getLog': ('POST', '/session/$sessionId/log')})

getlog = driver.execute('getLog', {'type': 'performance'})['value']

(在“getAvailableLogTypes”和“getLog”这两个添加的命令中,您只能在上面的代码片段中看到前者。后者只是返回远程 session 中可用日志类型的列表。)

现在我需要做的就是解释它....

关于python - 带有 python 的 selenium remotewebdriver-性能日志记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25504756/

相关文章:

C++ 错误 C2040 : 'e' : 'Logger' differs in levels of indirection from 'const std::exception &'

javascript - 使用 Selenium 截取屏幕截图元素?

python - 使用 Pyramid 和 rq 写入同一个日志文件

google-chrome - 将 Chrome 中的 console.log 保存到文件中

javascript - Protractor :无论选择下拉列表的可见性如何,始终获取选择选项状态 "displayed"

java - 我可以禁用 HtmlUnit WebDriver 在控制台中打印错误吗?

python - 如何从 python 中的切片列表中获取原始索引?

Python - flask : Static folder outside root directory

python - (使用 Python 的 OpenCV)使用 VideoCapture(1)/外部网络摄像头时出现不需要的自动旋转行为

python - 从 discord 使用 FFmpegPCMAudio 的问题