Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
I am trying to click on a button on a webpage/website. Whether it is a submit button or preview button or i agree button. The problem i am facing here is that i cannot click on few buttons because some websites have something like this:

<input type="reset" value="I do not agree"> <input type="submit" value="I agree">


and on some sites it is like this:

<button type="submit" name="preview">Preview</button>

In the 2nd example i am able to do the click event easily like this:
C#
private void preview()
       {
           HtmlElement ele = webBrowserCtl.Document.GetElementById("preview");
           if (ele != null)
           {
               ele.InvokeMember("click");
           }
       }


because in 2nd example i can use "name" and can go with it. But in the first code there is no "name" or even any "id" that i can use to find this specific button and clink on it than, it has just the "value". Can you kindly tell me how to do that in the cases like that? how to click on such buttons?
Regards.
Posted

1 solution

The issue is you need to know which form the button is in. Apart from that document.forms[x].submit(); is what you need. It's a fair guess that x is usually 0.
 
Share this answer
 
Comments
Member 9357064 25-Aug-12 10:14am    
but what if i am dealing with multiple sites? definitely i cannot hard code for every single one.
Regards.
Christian Graus 25-Aug-12 10:16am    
If it's not naming the form that it's submitting, the odds are low it has more than one. You can also just parse the form and work out how many forms are on it, and which one you're inside. why are you writing code to automate web site browsing in the first place ?
Member 9357064 25-Aug-12 10:27am    
May be it is not possible according to me because i do not have a proper values on my pages.
Christian Graus 25-Aug-12 10:38am    
Like I said the, forms[0].submit() will work.

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