我正在尝试从远程 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/