David Johnson
David Johnson

Reputation: 419

Clicking class button on website

I have the following code for a webpage;

<div class="toolbox">
<div class="toolboxNest" align="left">
<div class="clear"> </div>
<div class="gap"> </div>
<label for="j_username">
<input id="j_username" type="text" name="j_username">
<div class="clear"> </div>
<div class="gap"> </div>
<label for="j_password">
<input id="j_password" type="password" name="j_password">
</div>
<div class="clear"></div>
<div class="gap"></div>
<div align="center">
<input class="formButtonGreen" type="submit" value="Login">
</div>
<div class="clear"></div>
<div class="gap"></div>
<div class="infoText">

I am able to click and enter text for the username and password, but I cant work out how to press the submit button, if it were just an element then that would be fine, but it's in a class and I'm unsure how to do it.

This is my code...

var x = webBrowser1.Document.All.GetElementsByName("j_username");
  x[0].InnerText = "xxxxx";
  var y = webBrowser1.Document.All.GetElementsByName("j_password");
  y[0].InnerText = "xxxxxxxx";

//This part is not working....
 var s = webBrowser1.Document.GetElementById("formButtonGreen");
  s[0].InvokeMember("click");

Any one got any ideas?

Please note: I don't own the website so can't make changes to code behind webpage...

Thanks,

David

Upvotes: 0

Views: 424

Answers (2)

V4Vendetta
V4Vendetta

Reputation: 38230

You should try using .Document.Body.GetElementsByTagName("input") which should help you get the button element and later you can use InvokeMember("click") on that element.

This will return a collection of matching elements, so if there are more than one you will have to identify it from the attributes by looping over it and then trigger for the one you need.

Upvotes: 1

Flater
Flater

Reputation: 13813

Instead of clicking the button, just submit the form itself.

jQuery wise, this is:

$("#my_form").submit();

Or you coulkd use any other means to select that Form. By class, parent element, tag name, ...

Upvotes: 0

Related Questions