How to Get Http Response Code Using Selenium Webdriver

How to get HTTP Response Code using Selenium WebDriver

In a word, no. It's not possible using the Selenium WebDriver API. This has been discussed ad nauseam in the issue tracker for the project, and the feature will not be added to the API.

How to get the response status code with selenium?

In Selenium it's Not Possible!

For more info click here.

You can accomplish it with request:

import requests
from selenium import webdriver

driver = webdriver.get("url")
r = requests.get("url")
print(r.status_code)

Checking HttpResponse OK (200) with Selenium WebDriver

There is no way to get HTTP status codes directly in the WebDriver API. It has been a long-standing feature request, which will likely never be implemented in the project. The correct solution to your problem is to configure your browser to use a proxy which can intercept and log the network traffic, and have your code query that proxy for he result you're after.

Of course, if all you are interested in is checking a link to make sure it returns a 200 status code, you could easily just use an HTTP client library in whatever language you desire to navigate to the link. There's no need to use WebDriver unless you need to manipulate the resulting page in some way.

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)


Related Topics



Leave a reply



Submit