'How to get the response content in selenium?

When I open the URL with driver.get(url), how can I get the response content of the page? Please refer to the image for more information. enter image description here



Solution 1:[1]

In a separate post I saw this answer. As per it there is a ticket opened for Selenium.

Solution 2:[2]

I'm using Python and Django, but it's actually simple to get the response. I'm using a StaticLiveServerTestCase as my base test for the test. The .get() method on self.client actually returns the response itself. For example:

response = self.client.get(url)

However, it looks like what you're really trying to get is the cookie based on what you're pointing to in the picture. I use Django and the Django test suite to authenticate a user session to be used in the test.

def create_pre_authenticated_session(self, username, url="/"):
    user = User.objects.create(username=username)
    session = SessionStore()
    session[SESSION_KEY] = user.pk
    session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0]
    session[HASH_SESSION_KEY] = user.get_session_auth_hash()
    session.save()

    # to set a cookie we need to first visit the domain.
    # 404 pages load the quickest!
    self.browser.get(self.live_server_url + '/404_no_such_url/')
    self.browser.add_cookie(dict(
        name=settings.SESSION_COOKIE_NAME,
        value=session.session_key,
        secure=False,
        path='/',
    ))
    self.browser.get(self.live_server_url + url)
    return user

This has some other stuff in it that I borrowed from Percival's Test-Driven Development with Python, but I hope that it can provide some guidance on what you're trying to accomplish.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2