Matt
Matt

Reputation: 27

Is it possible for BrowserMob Proxy to capture HAR at specific intervals while Selenium (Python bindings) runs?

I'm trying to capture these events while navigating through the website and validate them against what events I'm expecting. I'm not even sure if BrowserMob Proxy + Selenium is even the right approach. Any help would be greatly appreciated.

enter image description here

Upvotes: 0

Views: 65

Answers (1)

Matt
Matt

Reputation: 27

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

Upvotes: 0

Related Questions