splinter icon indicating copy to clipboard operation
splinter copied to clipboard

use a proxy to get status code for selenum drivers

Open andrewsmedina opened this issue 7 years ago • 2 comments

I believe that we should use proxy to get status code in selenium driver. Something like browsermob: https://github.com/AutomatedTester/browsermob-proxy-py

andrewsmedina avatar Feb 11 '18 05:02 andrewsmedina

I like the idea, the only downside that I can think of from using browsermob is that it would require more dependencies on the system.

Is there a pure python proxy that could be used?

bmcculley avatar Feb 20 '18 01:02 bmcculley

You could always enable performance logs and parse the log to get the status code

in the capabilities dict

capabilities['loggingPrefs'] = {'performance': 'ALL'}

chrome options

chrome_options.add_experimental_option('perfLoggingPrefs', {"enablePage": True})

def parse_chromedriver_status_code(performance_log)

status_code = None

for log in performance_log:
    try:
        method = loads(log['message'])['message']['method']

        # it'll always be the 1st
        if method == 'Network.responseReceived':
            status_code = int(loads(log['message'])['message']['params']['response']['status'])
            # response_url = loads(log['message'])['message']['params']['response']['url']
            break

    except KeyError:
        pass

return status_code

craigmi avatar Mar 20 '18 18:03 craigmi