HTTP Status Code and Exceptions¶
Note: After 0.8 version the webdriver (firefox, chrome) based drivers does not support http error handling.
Dealing with HTTP status code¶
It’s also possible to check which HTTP status code a browser.visit gets. You can use status_code.is_success
to do the work
for you or you can compare the status code directly:
browser.visit('http://cobrateam.info')
browser.status_code.is_success() # True
# or
browser.status_code == 200 # True
# or
browser.status_code.code # 200
The difference between those methods is that if you get a redirect (or something that is not an HTTP error),
status_code.is_success
will consider your response as successfully. The numeric status code can be accessed via
status_code.code
.