Link to home
Start Free TrialLog in
Avatar of invader_RMUK
invader_RMUK

asked on

VB Internet Controls - How to click a button with no name

Hi there, I know how to enter in text to a website, and then click a button with this code.

wbrInternet is my Web Browser im using in my program.

I then do this:

      wbrInternet.document.all.item("textboxname").value = "Test"
      wbrInternet.document.all("Button").click

and that works fine. Fine if the button you want to click HAS A NAME.

This is the following HTML code of a site I wish to enter text into, and click the button. the button doesnt have a name and so I cant click it.

<form method="get" action="index.php" name="searchForm">
 <br>
  <br>
 <input name="text" type="text" size="30" autocomplete="off">
<select name="booke">
 <option value="vb6">Visual Basic 6</option>  
</select>
<input type="submit" value="Search Book">

</form>

How can I search that? I know I can do

wbrInternet.document.all.item("text").value = "Value I want"

but how do I do the click part?

Please help me.

Thanks
Avatar of edwardiii
edwardiii

Hi, invader_RMUK.

See this post's accepted answer--instead of trying to click a button, try submitting the form that your items are on:

https://www.experts-exchange.com/questions/21387130/Web-pages-that-use-input-from-user-Part-2.html

     wbrInternet.Document.Forms("login_form").Submit

And if that's no go, try looping through the elements/items and clicking each one, until you get the desired response.  Then note the details/id of the one that worked.
Private Sub Command1_Click()
    'WebBrowser1.Document.Forms("searchForm").Item(2).Value = "Search Book"
    Call WebBrowser1.Document.Forms("searchForm").Item(2).Click
End Sub


If the HTML is different for the Form (additional elements), then you may need to change (2) to the proper index.
ASKER CERTIFIED SOLUTION
Avatar of edwardiii
edwardiii

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Automating the submission of the form may cause problems if there are associated scripts (such as for OnClick event) for the Submit buttons. If the scripts do not execute, it may disrupt the data to be submitted. Another scenario may exist for forms that have different Submit-button elements as different values could be submitted.