Not able to save html page source of webpage

I have to save html page source of webpage and pass it to request endpoint.
I have done below code but I am not able to save .html

*** Settings ***
Library RequestsLibrary
Library SeleniumLibrary
Suite Setup Create Session example My Store

*** Test Cases ***
Example using the requests library
    ${response}=    Get     http://automationpractice.com/index.php
    log     ${response.content}
    Open Browser    http://automationpractice.com/index.php     chrome
    ${myHtml} =    Get Source
    Log To Console    ${myHtml}
    Close All Browsers

Hi Bk-ava,

In both cases what you have is the content of the page returned i.e. the html content of a .html file, now you just need to save it into a file.

Operating System library’s Create File or Create Binary File are probably what you want, I would guess something like one of these:

Create Binary File    ${CURDIR}${/}content.html    ${response.content}
Create File    ${CURDIR}${/}text.html    ${response.text}
Create File    ${CURDIR}${/}myHtml.html    ${myHtml}

Not really sure why you would want to save the page as a html file as you should be able to do all the tests you need with the responses variables you had? but I’m sure you have a reason.

Dave.

Thanks @damies13
Solution worked fine

1 Like