问题
I'm trying to get back some performance log info from a remote webdriver instance. I'm using the Python Selenium bindings.
From what I can see, this is information I should be able to get back. Think it may only be available with ChromeDriver. I'm currently using FireFox but can easily switch over if it gets the info I want.
However, I'm new to Python (but learning!) and documentation around the capabilities dictionaries (when used for performance logging) for Python seems to be a bit limited (or my google-fu is weak this morning).
I've found the following:
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);
Which looks like it should do what I need. But it's Java. I'm not quite sure how I'd go about converting this to Python. Assuming it's possible.
Any ideas?
回答1:
In case anyone is wondering, this seems to do the trick for me:
(Assuming you're using 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']
(Of the two added commands 'getAvailableLogTypes' and 'getLog' - you only see the former in the above code snippet. The latter simply returns a list of the available log types on your remote session.)
Now all I need to do is interpret it ....
回答2:
After playing around with the Chromedriver log for a while, I found a more compact solution that works on browsers other than Chrome.
This: https://pypi.python.org/pypi/seleniumwrapper
Which adds a nice wrapper round the Navigation Timing API (https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/NavigationTiming/Overview.html). Gives a far more compact set of data and is much easier to interpret and use.
The other wrappers it puts round standard Selenium are actually quite nice too!
来源:https://stackoverflow.com/questions/25504756/selenium-remotewebdriver-with-python-performance-logging