@Nicholas Nguyen , based on your description, you could try the following code to login into a website in the winform:
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate("https://somesite.com/");
}
private void button1_Click(object sender, EventArgs e)
{
if (webBrowser1.ReadyState == WebBrowserReadyState.Complete)
{
HtmlDocument htmlDoc = this.webBrowser1.Document;
////set account
HtmlElement id = htmlDoc.GetElementById("username");
id.SetAttribute("value", txtName.Text.Trim());
//set password
HtmlElement pwd = htmlDoc.GetElementById("password");
pwd.SetAttribute("value", txtPassword.Text.Trim());
//login
var btn = htmlDoc.GetElementsByTagName("div").Cast<HtmlElement>().Where(i=>i.InnerText== "sign in ").First();
if (btn != null)
{
btn.InvokeMember("click");
}
}
}
Note: We need to achieve the htmlelement for username, password and sign in button and set the value for username and password and finally click the button.
Example html:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.