get http status code python selenium get http status code python selenium selenium selenium

get http status code python selenium


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)


Edited your example.Try to use requests library.

from requests import getself.driver.get(link)request = get(link)if not request.status_code == 200:  print('http status: ' + str(request.status_code))

Hope, this will help you.