In a C# winform project I am using a webbrowser object to log into a website, navigate to a particular list and then work with that list. After logging in I need to select from some dropdown selection choices that are inside a form and then submit the form (there is no submit element - submitting the form is done by clicking on an image anchored with an onclick event, all as shown below.
Here's an abbreviated version of the code at the target site (I've shortened it quite a bit - i think I left everything pertinent in. I've also cut out all the styles to focus on the HTML and javascript). Here's the code:
<form name="frm1" id="frm1" action="/tab/formaction.asp" method="post">
<table>
<tr><td> Locations</td></tr>
<tr><td>
<table>
<tr>
<td>Origin</td>
<td>
<select title="Choose Origin Location(s)" name="origin_location"
id="origin_location" multiple="multiple">
<option value="0">ANYWHERE</option>
<option value="1">North West</option>
<option value="2">North Central</option>
<option value="3">Great Lakes</option>
<option value="4">North East</option>
<option value="5">South West</option>
</select>
</td>
</tr>
<tr>
<td>Destination</td>
<td>
<select title="Choose Destination Location(s)"
name="destination_location" id="destination_location"
multiple="multiple">
<option value="0">ANYWHERE</option>
<option value="1">North West</option>
<option value="2">North Central</option>
<option value="3">Great Lakes</option>
<option value="4">North East</option>
<option value="5">South West</option>
</select>
</td>
</tr>
<tr>
<td>Number of People</td>
<td>
<select name="people">
<option value="1">1+</option>
<option value="2">2+</option>
<option value="3">3+</option>
<option value="4">4+</option>
</select>
<select style="visibility:hidden;" name="equality">
<!--
<option value="<=">Less than or Equal</option>
<option value="=">Equal</option>
!-->
<option value=">=">Greater than or Equal</option>
</select>
</td>
</tr>
<tr>
<td>
<a href="javascript: void 0;" onclick="objForm.submit(); return
false;">
<img src="/tab/images/buttons/submit.gif" border="0"
WIDTH="71" HEIGHT="21">
</a>
</td>
</tr>
</table>
</td></tr></table>
<input type="hidden" name="origin_text" id="origin_text">
<input type="hidden" name="origin_region_id" id="origin_region_id">
<input type="hidden" name="origin_state_id" id="origin_state_id">
<input type="hidden" name="origin_city_id" id="origin_city_id">
<input type="hidden" name="destination_text" id="destination_text">
<input type="hidden" name="destination_region_id"
id="destination_region_id">
<input type="hidden" name="destination_state_id" id="destination_state_id">
<input type="hidden" name="destination_city_id" id="destination_city_id">
<input type="hidden" name="equality_text" id="equality_text">
<input type="hidden" name="sZip" id="sZip">
</form>
What I have tried:
My first thought was to set attributes for the first and second of the three things I want to choose, like this:
<pre>webBrowser1.Document.GetElementById("origin_location")
.SetAttribute("value", "4");
webBrowser1.Document.GetElementById("destination_location")
.SetAttribute("value", "4");
I am not sure that I am doing those 2 correctly, and for the third, there is no ID, so I have no idea how to select it.
Finally, I want to click the anchored image or to invoke the onclick script in the cell that reads:
<a href="javascript: void 0;" onclick="objForm.submit(); return false;">
<img src="/tab/images/buttons/submit.gif" border="0" WIDTH="71"
HEIGHT="21">
</a>
As might be obvious, I am a fairly new coder and appreciate any help or guidance.