Reputation: 376
Is there any way to log http requests/responses using Selenium Webdriver (firefox)?
I guess it's possible to drive web traffic through proxy and log it, but maybe there is more simple "internal" selenium solution?
Asked this question on #selenium channel:
you will need to proxy it to capture the requests
so, looks like only way to setup proxy for it.
Upvotes: 5
Views: 4549
Reputation: 14338
Now year 2021, answer is: YES.
you can use the new lib: selenium-wire
selenium-wire
pip install selenium-wire
change from
from selenium import webdriver
to
from seleniumwire import webdriver
after driver.get(yourUrl)
, add:
# Access requests via the `requests` attribute
for request in driver.requests:
if request.response:
print(
request.url,
request.response.status_code,
request.response.headers['Content-Type']
)
can got your expected request
and response
.
Upvotes: 6
Reputation: 27496
No, WebDriver doesn't have any methods to examine or modify the HTTP traffic occurring between the browser and the website. The information you've already gotten from the Selenium IRC channel (likely even from a Selenium committer) is correct. A proxy is the correct approach here.
Upvotes: 3