How to InvokeMember using HtmlAgilityPack

c# html-agility-pack login

Question

I want to use HtmlAgilityPack class to login. But I don't know how.

This is what I've tried. But it's not working.

txtUserName.Text = "username";
txtPassword.Text = "password";
HtmlAgilityPack.HtmlDocument doc = new HtmlWeb().Load("about:Tabs");
doc.GetElementbyId("username").SetAttributeValue("value", txtUserName.Text);
doc.GetElementbyId("password").SetAttributeValue("value", txtPassword.Text);
foreach (HtmlNode node in doc.DocumentNode.SelectNodes("//button[@class='btn login-btn blue pull-right btn-primary']"))
 {
    node[0].InvokeMember("click");//wrong code
 }

I cannot use WebBrowser class.

Accepted Answer

I found a way to login using Selenium and I think it's the best way to do it:

IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl("Your Address Login");
IWebElement query = driver.FindElement(By.Id("username"));
query.SendKeys("Your Username");
query = driver.FindElement(By.Id("password"));
query.SendKeys("Your Password");
query.Submit();

download selenium for dotnet

After download add reference WebDriver.dll and use namespace OpenQA.Selenium.Firefox;

Learn more Here


Popular Answer

HtmlAgilityPack can only parse html.

Use WebClient instead.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow