Using .Net web browser to fill out a form to click a radio button

carthorn

New member
Joined
Aug 14, 2008
Messages
2
Programming Experience
10+
Hi guys and gals,

I am trying to fill out a web form using a vb windows form and the .net web browser in 2005. I have tried everything from going element by element to trying to use the invoke("click"), etc. The form is in a frame on the page which I can access just fine, I can access and fill out the textbox and click on images in the form but unable to access the radio buttons as it states that I am referencing a "null" value.

Below is the form


This is a VB script that it call onClick:

VB.NET:
Sub fnSelObject(ByVal strObjectType)
	Document.InputForm.action = "SearchObjects.asp"
	Document.InputForm.target = ""
	Document.InputForm.Method = "post"
	document.InputForm.ObjectType.Value = strObjectType
	document.InputForm.LDAPActCriterion.Value = "."
	document.InputForm.Submit
end Sub

Here is the form (some of it has been excluded):

VB.NET:
<FORM NAME='InputForm' ACTION='SearchObjects.asp' METHOD='POST'>


	<table width=100% cellpadding=2 cellspacing=0>
		<tr class=inputFieldA>
			<td width=16%>
				
				<INPUT  type=radio id=rbObject name=rbObject CHECKED OnClick='fnSelObject("user")'>User</INPUT>
			</td>
			<td width=16%>
				
				<INPUT  type=radio id=rbObject name=rbObject  OnClick='fnSelObject("Group")'>Group</INPUT>
			</td>
			<td width=16%>
				
				<INPUT  type=radio id=rbObject name=rbObject  OnClick='fnSelObject("Resource")'>Resource</INPUT>
			</td>
			<td width=16%>
				
				<INPUT  type=radio id=rbObject name=rbObject  OnClick='fnSelObject("OU")'>OU</INPUT>
			</td>
			<td width=16%>
				
				<INPUT  type=radio id=rbObject name=rbObject  OnClick='fnSelObject("Computer")'>Computer</INPUT>
			</td>

<INPUT type=hidden id=ObjectType name=ObjectType Value='user'>
	<INPUT type=hidden id=ActCriterion name=ActCriterion Value='Name'>
	<INPUT type=hidden id=ActProvider name=ActProvider Value='All Provider'>
	<INPUT type=hidden id=ActExactSearch name=ActExactSearch Value='CHECKED'>
	<INPUT type=hidden id=LDAPActCriterion name=LDAPActCriterion Value='cn'>
	<INPUT type=hidden id=ActAction name=ActAction Value='SEARCHOBJECTS'>
	<INPUT type=hidden id=StatusFilter name=StatusFilter Value=''>
	<INPUT type=hidden id=MultiMode name=MultiMode Value=''>

As long as it runs the function or uses the click method, I really don't care but this is driving me crazy. Any help would be great!

Thanks!
 
Get the input elements from the first document form
WebBrowser1.Document.Forms(0).GetElementsByTagName("input")
check if type attribute is "radio"
If el.GetAttribute("type") = "radio" Then
set checked attribute
el.SetAttribute("checked", "checked")
invoke onclick event
el.InvokeMember("onclick")
 
Thanks for the reply!

That code works great, but I found that's not the reason I was having the issue. The site loaded 2 windows that I was not accounting for, so when it looked for the elements on the page they were Null because they were not loaded yet! Doh!

Had to change around my Browserloaded event
 
Get the input elements from the first document form

check if type attribute is "radio"

set checked attribute

invoke onclick event

Im doing the same as the thread owner.. but i dont understand what the "el.GetAtteribute" thingy is.. What is el??
Could someone write a little snippet please? :p
 
"el" is an element from the GetElements call, the type of those is htmlElement.
 
Back
Top