Hi guys
I'm trying to make a autofilling web browser on c# and their is a checkbox I need to check.
The web id of it is cb_rules_agree and I cant work out how to automatically click the textbox when i load the web browser through c#.
I tried this but it didnt work
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
webBrowser.Document.GetElementById("cb_rules_agree").SetAttribute("value", checkbox.check);
}
If someone could tell me how to automatically set the checkbox and checked I would be very very grateful.
Thanks John
Loading
Zoran HorvatPosted Nov 27, 2010, 5:18 AM
In this example, I'm opening Google search preferences page. It contains a checkbox with id=nwc, which indicates whether to open search in new window (checked) or not (not checked). This checkbox is (in my case) not checked by default, and code below checks it as soon as document opens.
using System;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
webBrowser1.DocumentCompleted += new WebBrowserDocumentCompletedEventHandler(webBrowser1_DocumentCompleted);
}
void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
mshtml.HTMLInputElement el = webBrowser1.Document.GetElementById("nwc").DomElement as mshtml.HTMLInputElement;
object o = el.getAttribute("checked");
el.setAttribute("checked", "true");
}
private void Form1_Load(object sender, EventArgs e)
{
webBrowser1.Navigate(@"http://www.google.com/preferences?hl=en");
}
}
}