Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get status code by using selenium.py (python code)

I am writing a selenium script by python, but I think I don't see any information about:

How to get http status code from selenium Python code.

Or I missing something. If anyone found that, please feel free to post.

like image 666
maa_modd Avatar asked Apr 27 '11 04:04

maa_modd


People also ask

How do I get response status code in Selenium?

You can obtain the response code in Java by using URL. openConnection() and HttpURLConnection. getResponseCode() : URL url = new URL("http://exampleurl.ex"); HttpURLConnection httpURLConnection = (HttpURLConnection) url.

How do you check if an element is displayed or not in Selenium Python?

is_displayed() element method – Selenium Python.

Can I find element by class Selenium Python?

Luckily, Selenium offers a few methods you can use to find elements. One of the options the Selenium WebDriver library provides for locating HTML elements is the use of the class property. The HTML class property is used for setting a class to an HTML element.


1 Answers

It's Not Possible.

Unfortunately, Selenium does not provide this information by design. There is a very lengthy discussion about this, but the short of it is that:

  1. Selenium is a browser emulation tool, not necessarily a testing tool.
  2. Selenium performs many GETs and POSTs during the process of rendering a page and adding an interface for that would complicate the API in ways the authors resist.

We're left with hacks like:

  1. Look for error information in the returned HTML.
  2. Use another tool instead like Requests (but see the shortcomings of that approach in @Zeinab's answer.
like image 81
mlissner Avatar answered Sep 30 '22 11:09

mlissner