How can I get the http status code in python if I open a link? I did it this way, but it always shows 200 even if the page throws a 404 error...
from urllib.request import *
self.driver.get(link)
code = urlopen(link).getcode()
if not code == 200:
print('http status: ' + str(code))
That's the problem, Selenium will always find a page. You have 2 ways to check if loading didn't work :
1 : Check content
self.assertFalse("<insert here a string which is only in the error page>" in self.driver.page_source)
2 : Use Django test Client
response = self.client.get(link)
self.assertEqual(response.status_code,200)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With