pythonselenium-webdrivergoogle-chrome-devtoolsadobe-analytics

Is there a way to detect when an Adobe Analytics event is sent while Selenium is running?


I'm running Selenium with Python bindings and I'm trying to figure out a way to detect which events are being sent as Selenium interacts with elements and pages. These events are listed in the network tab in Chrome Developer Tools, under Payload > Query String Parameters. Ideally, I'd like to run the test and print out the events that were sent while the test ran.

I tried capturing HAR data with Browsermob-proxy, but I'm already running a proxy, so it's adding too many layers of complexity for me. I feel like I'm overthinking it, considering I only need to grab values from the dev tools at certain intervals.


Solution

  • The answer to my problem is Selenium-wire

    Then you can use the built-in requests functionality to loop through the requests.

    def event_checker(driver):
    event_list = []  # Initialize event list
    time.sleep(9)  # Wait for the request
    for request in driver.requests:  # Iterate through network requests
            query = request.querystring.replace('&', ' ')  # Replace ampersand with space
            query = query.split()  # Split on space into a list of requests
            for items in query:  # Iterate through items in query
                if "events" in items:  # If the word "events" is in an item
                    items = items.replace('%3D', '=')  # Replace unicode '=' with '='
                    items = items.replace('%2C', ' ')  # Replace unicode ',' with space
                    items = items.replace('%3A', ':')  # Replace unicode ':' with ':'
                    items = items.split()  # Split on space into a list of events
                    for e in items:  # Iterate through the list of events
                        if "events=" in e:  # Strip "events=" label
                            e = e.replace('events=', '')
                        event_list.append(e)  # Append the event to the event list
    return event_list  # Return the page title and event list