2

I'm trying to use HtmlAgilityPack with Selenium. I want to make some test, but don't know how to load HtmlDocument from Selenium Driver.PageSource String. Any help? (c# or vb.net)

Here the code...

Dim driver As IWebDriver
Dim ChromeOptions As New ChromeOptions
driver = New ChromeDriver("C:\ChromeDriver", ChromeOptions)
driver.Navigate.GoToUrl("www.Google.com")

Dim doc As New HtmlDocument
Dim wb As New HtmlWeb
doc = wb.LoadFromBrowser(driver.PageSource)

N.B. My Question regard interaction between Selenium and HtmlAgilityPack.

Marcello
  • 438
  • 5
  • 21
  • You mean _download_ the `htmlDocument` and save it inside a variable? – Simo Sep 21 '18 at 09:49
  • @Simo Yes, from the Selenium Driver.PageLoaded String. – Marcello Sep 21 '18 at 09:54
  • Possible duplicate of [how to get innerHTML of whole page in selenium driver?](https://stackoverflow.com/questions/35905517/how-to-get-innerhtml-of-whole-page-in-selenium-driver) – Simo Sep 21 '18 at 09:58
  • @Simo It's in Pyton.but maybe could be a good help, ...let's me try. – Marcello Sep 21 '18 at 10:01
  • Yes but the syntax is pretty similar and at least it can give you some ideas! – Simo Sep 21 '18 at 10:05
  • 1
    @Simo Yes, thank you Simo, with ChromeDriver, need to do something with JavaScriptExecutor, working on it. – Marcello Sep 21 '18 at 10:10
  • @Simo Thanks Simo, i examined the issue: your help is good, but in the post you sent me, the argument is another, just how to get iWebElements (in Python); my question it's on the interaction between Selenium and HtmlAgilityPack, I've found and post the solution, but thanks anyway for your help!! – Marcello Sep 21 '18 at 12:42

1 Answers1

5

I found the solution: When we want to interact between Selenium and HtmlAgilityPack, we don't need to create an instance of HtmlWeb, because we have already the Selenium Browser. So just load the HtmlDocument directly from the Driver.PageSource:

Dim driver As IWebDriver
Dim ChromeOptions As New ChromeOptions
driver = New ChromeDriver("C:\ChromeDriver", ChromeOptions)
driver.Navigate.GoToUrl("www.Google.com")

Dim doc As New HtmlDocument
doc.LoadHtml(driver.PageSource)

Since there are not many similar help on internet, regarding interaction between Selenium and HtmlAgilityPack, i publish myself the answer, maybe can be in help.

Marcello
  • 438
  • 5
  • 21