1

I'm trying to capture all network logs using seleniumwire. When chromedriver is in normal mode, it is able to capture all requests. But when it is in headless mode, it is not capturing all requests.

I tried adding sleep(10), assert driver.last_request.response.status_code == 200 but neither helped.

Since seleniumwire is not that popular, I'm adding a sample guide below in the hope of getting people with knowledge of selenium to try a hand to help me fix the problem.

Working with seleniumwire

Installing seleniumwire

pip install seleniumwire

Sample script:

from seleniumwire import webdriver  # Import from seleniumwire

# Create a new instance of the Chrome driver
driver = webdriver.Chrome()

# Go to the YouTube homepage.
driver.get('https://www.youtube.com')

# Access requests via the `requests` attribute
for request in driver.requests:
    if request.response:
        print(
            request.path,
            request.response.status_code,
            request.response.headers['Content-Type']
        )

1 Answers1

0

When chrome browser is opened by selenium, it uses it's own profile rather than the default one present. Try using custom profile, for chrome you can use ChromeOptions class use a custom profile and try.

Kaushik
  • 71
  • 8
  • Are you telling that, headless and normal mode of chrome-driver uses different profile ? If yes, What all options should i add in order to make it work in headless mode ? Else can you make it more clear. –  Nov 13 '18 at 10:20