Interact with html request response

I need to test a logon api that is accessed through a get request.
The response is an html containing a login page where I must inform user, password and then click on logon button.

Then it returns two tokens and the expire time of such tokens. With this response I’ll be able to interact properly with the api.

Does anyone know a way to interact with the html through requests library or open this html with selenium library?

Also, if using selenium library, does anyone know a way to retrieve the response header?

Hi Paulo,

I suggest first you step through the authentication manually in a browser with dev tools open to the network tab, this will show you the get request and more importantly the subsequent post request, you will want to pay close attention to the request headers and request body for this post call.

Once you have that information, use the session functions in the requests library, you will want to use, Create Session, GET On Session (to load the login page) and then POST On Session to perform the login. referring to the documentation to generate a post body and headers that match what you see in dev tools.

If you are really lucky the tokens you mentioned are just cookies or session headers that requests will handle for you, but if not and they are returned in the response body of the post, then refer to Usage and Response Object for how to get the tokens out of the response.

Hope this helps,

Dave.