Raky
Raky

Reputation: 902

Selenium Create new HTML Document from ChromeWebElement

Using VB.net 2019 and Selenium I intend to create a new .htm document by reading ChromeWebElement and prefixing/suffixing requisite statements. Something like this:-

Dim ele As OpenQA.Selenium.Remote.RemoteWebElement = driver.FindElementByClassName("textLayer")
Dim stringForFile = "<!DOCTYPE html><meta charset = "UTF-8" ><html>_
           <head><link rel ='stylesheet' href='viewer.css'></head></head><body>" _
            + ele + "</body></html>"

However, the above chunk of code is not allowing such string manipulation for obvious reasons of Casting error of ele from OpenQA.Selenium.Remote.RemoteWebElement to String.

Is there a way to prefix and append HTML tags to Selenium WebElement and save them as a new htm file?

Upvotes: 1

Views: 84

Answers (1)

user5997151
user5997151

Reputation:

If I'm correct, you're trying to fetch the html of the element, prefix/suffix it and store it in a variable/file.

The problem is, you're trying to string + RemoteWebElement, while you should be doing this:

Dim stringForFile = "<!DOCTYPE html><meta charset = "UTF-8" ><html>_
       <head><link rel ='stylesheet' href='viewer.css'></head></head><body>" _
        + ele.GetAttribute("innerHTML") + "</body></html>"

Upvotes: 1

Related Questions