Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# check/uncheck checkbox in WebBrowser control?

This is my code:

webBrowser1.Document.GetElementById("user").SetAttribute("value", txtUsername.Text);
webBrowser1.Document.GetElementById("pass").SetAttribute("value", txtPassword.Text);
webBrowser1.Document.GetElementById("rememberme").SetAttribute("checked", cbAutoLogin.Checked.ToString());

The username and password is ok I don't have any problem, but the check is not working. The problem is not on the cbAutoLogin.Checked.ToString(), even if I write true or false nothing change.

Here is the checkbox on html

<input type='checkbox' id='rememberme' checked='checked' name='rememberme' value='1' class='input_check' />

Anyone else have the same problem? Or I do something wrong?

like image 203
a1204773 Avatar asked Jun 29 '12 03:06

a1204773


1 Answers

Use this:

webBrowser1.Document.GetElementById("rememberme").InvokeMember("CLICK");

It will make it checked if unchecked and Unchecked if Checked.

OR change the value attribute same like username,password to 0 or 1.

like image 117
confusedMind Avatar answered Oct 20 '22 09:10

confusedMind