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:
- Selenium is a browser emulation tool, not necessarily a testing tool.
- 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:
- Look for error information in the returned HTML.
- Use another tool instead like Requests (but see the shortcomings of that approach in @Zeinab’s answer.