Click here to Skip to main content
15,883,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,

I am trying to check a checkbox on a webpage that has been loaded through the webbrowser control.

This is the code from the webpage

XML
<div class="uploadFormLine" id="uploadTerms">
        <input type="checkbox" name="terms" id="terms" onclick="checkTerms()" />
        <label for="terms"><strong></strong></label>
      </div>



I have tried

HtmlElement checkBox = doc.GetElementById("terms");
checkBox.InvokeMember("Click");

and...

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


neither of them are working..any help would be appreciated...thank you!
Posted
Comments
Krunal Rohit 17-Oct-15 0:13am    
You want the checkbox to be checked when page is loaded, right ?

-KR
CBO1987 17-Oct-15 0:20am    
Yes sir

you need WebBrowser.DocumentCompleted Event[^]
sample code:
C#
webBrowser1.DocumentCompleted +=
        new WebBrowserDocumentCompletedEventHandler(DoSomething);
private void DoSomething(object sender,
    WebBrowserDocumentCompletedEventArgs e)
{
    // find checkbox and invoke here...
}
 
Share this answer
 
Hey,

Thank you for the reply. Sorry, I forgot to mention I do have that code. I have code in the same block working with a text box on the page but for some reason it won't respond to the check box. I think it may have something to do with the html in the code "onclick" or a confusion with another id named "terms". I also tried focusing the text box which worked but would not click. I'm not sure really...it might also have to do with parent or child elements. If there is anyone that has solved this before any help or direction would be appreciated and hopefully my problem is clear. Thank you.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900