Enrico Detoma
Enrico Detoma

Reputation: 3179

Catching continuous requests with seleniumwire

I have a website that continuously makes AJAX requests (about 1 per second).

I would like seleniumwire to simply keep the browser open and catch all these requests, without having to refresh the page, but I couldn't find a way to do it, i.e.

for request in driver.requests:
    ...

will return the requests made while loading the page, but not all subsequent requests, even if I try to use:

chrome_options.add_experimental_option("detach", True)

Is there a way to keep seleniumwire catching AJAX requests continuously on a loaded web page?

Upvotes: 0

Views: 947

Answers (1)

Enrico Detoma
Enrico Detoma

Reputation: 3179

Just found the solution myself: I need to use an interceptor:

def interceptor(request, response):
    print(
        request.url,
        response.status_code,
        response.headers['Content-Type']
    )

driver.response_interceptor = interceptor

Then I can simply do time.sleep(1000000) after driver.get(...) and wait for responses to arrive.

Upvotes: 0

Related Questions