How to get status code by using selenium.py (python code)

It’s Not Possible.

Unfortunately, Selenium does not provide this information by design. There is a very lengthy discussion about this, but the short of it is that:

  1. Selenium is a browser emulation tool, not necessarily a testing tool.
  2. Selenium performs many GETs and POSTs during the process of rendering a page and adding an interface for that would complicate the API in ways the authors resist.

We’re left with hacks like:

  1. Look for error information in the returned HTML.
  2. Use another tool instead like Requests (but see the shortcomings of that approach in @Zeinab’s answer.

Leave a Comment