Last active
October 26, 2016 15:30
-
-
Save lambdaX/35a62c2292aace0fac47c339fdfeee55 to your computer and use it in GitHub Desktop.
selenium_chromedriver_performance.py by @klepikov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This does not include WebPageTest submission, only an illustration | |
# how to use the Logging API from the WebDriver Python bindings. | |
from selenium import webdriver | |
from selenium.webdriver.common import keys | |
driver = webdriver.Chrome( | |
executable_path="chromedriver2_server", | |
desired_capabilities={'loggingPrefs': {'performance': 'INFO'}}) | |
# Hack the Logging API into the Python remote driver. | |
# Not implemented in Selenium, patch welcome!! | |
driver.command_executor._commands.update({ | |
'getAvailableLogTypes': ('GET', '/session/$sessionId/log/types'), | |
'getLog': ('POST', '/session/$sessionId/log')}) | |
try: | |
print 'Available log types:', driver.execute('getAvailableLogTypes')['value'] | |
driver.get('http://news.google.com') | |
elem = driver.find_element_by_name('q') # Find the query box | |
elem.send_keys('GTAC 2013' + keys.Keys.RETURN) | |
elem = driver.find_element_by_link_text('Web') | |
elem.click() | |
print 'Profiler log:', driver.execute('getLog', {'type': 'performance'})['value'] | |
finally: | |
driver.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment