1

Using java, I can get the http response code of a url (like this), and using selenium I am able to get all elements from a webpage (like this).

Is there a way I can get the response code of an element? Because an element is not a link, its not like getting the response of a url. (which is what all the other stack overflow questions go over.)

Really, I'm just trying to see if all the elements of a webpage were loaded (got a response 200) and to see which ones did not load (maybe they got a response 404). Like on the network tab in browser inspect. (Is there some built in selenium feature that allows access to the network tab? I couldn't find any.)

Update: I was calling it 'element' in the question, but I found out it is actually called 'resource'.

Example of browser Network Tab

network tab

Alex
  • 141
  • 1
  • 13
  • 2
    Possible duplicate of [How to get HTTP Response Code using Selenium WebDriver](https://stackoverflow.com/questions/6509628/how-to-get-http-response-code-using-selenium-webdriver) – Kiril S. Sep 05 '18 at 17:01
  • I already checked that one. That one only deals with getting the status code from a url. – Alex Sep 05 '18 at 18:20
  • Same thing. The accepted answer says it all really. – Kiril S. Sep 05 '18 at 18:40
  • It's not the same, that is trying to use Selenium WebDriver to get the response of the page. I need to get the response of all elements on the page, whether that be using java, selenium or some other tool. I need response of an element, not the page.... Can you take off the "This question may already have an answer here: ..." – Alex Sep 06 '18 at 11:04

1 Answers1

1

This can go very subjective. First Selenium is not a tool to achieve what you are looking at and as far as I know Selenium does not have any interface to introspect the browser debugging/developer tools. You may use the browser's native developer APIs to query the network tab and its events.

Now coming to HTTP Response, a status code = 200 does not guarantee that all the elements are loaded, just because of the nature of modern web applications and dynamic content in them. When you say https Response, it gets associated with a Resource. Mostly nobody treats a web element as a Resource.

What you have highlighted in the image is a couple of javascript not loaded.

  • For the website I will be using this for, sometimes there is a new deployment and some of those resources (image, text, whatever..) don't load. I just need to get the status code of all the resources (not the page). I have done a little more research and it looks like [this answer](https://stackoverflow.com/a/44474647/8854270) is what I need. it gets the network tab content and puts in a json format in .har file. – Alex Sep 07 '18 at 11:41