简体   繁体   中英

How to get HtmlAgilityPack.HtmlDocument from Selenium Driver.PageSource?

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)

NB My Question regard interaction between Selenium and HtmlAgilityPack.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM