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
How to Update Each Element in a List in Java 8 Using Stream API
Check If a Given Time Lies Between Two Times Regardless of Date
How to Create a Spring JPA Repository Findby Query Using a Property That Contains a Keyword
How to Check Json in Response Body With Mockmvc
How to Return a HTML Page from a Restful Controller in Spring Boot
In Java, How to Determine If a Char Array Contains a Particular Character
Regex to Match a String Not Starting or Ending With a Pattern
Missing Method Body, or Declare Abstract in Java
Query in Repository With Limit
Alternative to Switch Case in Java
Spring Boot - How to Get Running Port and Ip Address
Finding Repeated Words on a String and Counting the Repetitions
String Match of Only 3 Specific Words
Java Stream Collectors.Groupingby() Multiple Fields
Why Am I Getting the Error "The Method Is Undefined for the Type"
Retrieving Data from Biometric Fingerprint Attendance Device