wkeeling / selenium-wire

Extends Selenium's Python bindings to give you the ability to inspect requests made by the browser.
MIT License
1.9k stars 251 forks source link

Clear driver.requests list after visiting a webpage #590

Closed extratrees closed 2 years ago

extratrees commented 2 years ago

Hello, First of all kudos for this great library. This is not a true issue rather than a question. I was wondering if there was the possibility of clearing the requestsattribute of the webdriver before visiting a new page, as I would like to avoid stopping and restarting a new driver for each web page.

wkeeling commented 2 years ago

Have you tried del driver.requests? E.g

driver.get(...)  # visit a page 

del driver.requests  # clear requests 

driver.get(...)  # visit a new page
hedonistrh commented 2 years ago

Thanks @wkeeling, that was not my issue but I needed that information as well. That is working very well and. 🙏🏼

Ps. Thanks for great library. 💯

maxp-hover commented 1 year ago

Hi, I would request / recommend adding a way for this del driver.requests call to be atomic, e.g. in this example:

driver.get(...)  # visit a page 
del driver.requests  # clear requests 
driver.get(...)  # visit a new page

It seems to be possible that driver.requests still gets populated by the first page after the del driver.requests call.

Ideally, we could be guaranteed that the second driver.get call would start with an empty driver.requests, so we could know exactly which requests were associated with that page.