YasserKhalil
YasserKhalil

Reputation: 9568

Load html body innerHTML using Selenium

I am searching for a way to load the HTML body into selenium bot

html.body.innerHTML = .responseText

'
Set bot = New Selenium.ChromeDriver
bot.Get HERE

Is it possible to do such a task or I have to save the html body to a file then navigate to that file?

I could manage that by exporting the html body to a file using this procedure

Sub ExportHTML(sInput As String)
    With CreateObject("ADODB.Stream")
        .Charset = "UTF-8"
        .Open
        .WriteText sInput
        .SaveToFile Environ("USERPROFILE") & "\Desktop\OutputHTML.html", 2
        .Close
    End With
End Sub

After that I could load the file using the selenium driver like that

bot.Get "file:///" & Environ("USERPROFILE") & "\Desktop\OutputHTML.html"

Upvotes: 0

Views: 204

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193388

You can't load the HTML body seperately as the HTML Document in it's core form consists of two manadatory parts:

  • The <head>
  • The <body>

Example of a simple HTML document:

<html>
  <head>
    <title>Title of the document</title>
  </head>

  <body>
    <h1>This is a heading</h1>
    <p>This is a paragraph.</p>
  </body>

</html>

Upvotes: 1

Related Questions