Interacting with items in a web browser control

lmm07

New member
Joined
Jul 12, 2007
Messages
2
Programming Experience
1-3
(Vb.net 2005 express)
Kinda stumped when it comes to web controls....

Okay the basic layout:
Two panels.
Panel1 : Bunch of text boxes and such
Panel2 : has Web Browser Control


Looking to: put text from mytextbox.text into a text box in the web control
(The web control is

Bit of code for the text box in the web control:
HTML:
<label>Username</label><input type="text" name="username" tabindex="1">

Another thing, if possible:
Code to "Click" an image (The image is actually a link)

Code for that image
HTML:
<input type="image" src="http://mysite.com/sign_in.jpg" tabindex="4" alt="Sign In" title="Sign In" 
width="80" height="21" style="margin-left: 4px; vertical-align: bottom"/></div>


Where i got stuck at:
VB.NET:
WebBrowserControl1.Document.All("username").Value = "DoeJohn321"
Not sure why it wont work =/



Thanks a ton for any help!
 
Last edited by a moderator:
WebBrowserControl1.Document.All("username").Value = "DoeJohn321"
You may use the SetAttribute Function
VB.NET:
Me.WebBrowser1.Document.All("Id of html element").SetAttribute("Value", "new value")
Code to "Click" an image (The image is actually a link)
You may use the RaiseEvent method
VB.NET:
Me.WebBrowser1.Document.All("Id of HtmlElement").RaiseEvent("EventName")
 
Not sure why it wont work
You don't have a control with ID "username" and HtmlElement don't have a Value property.

ajeeshcos SetAttribute and RaiseEvent suggestions work, but you have to use the GetElementsByName to get the element with name "username". GetElementsByName returns a collection of all elements with that name, so you have to figure out which one if there exist more than one.

Here's an example that sets the Value attribute for the first element by name "username":
VB.NET:
WebBrowser1.Document.All.GetElementsByName("username")(0).SetAttribute("value", "the value")
 
Ive gotten the setattribute to work, but having alot of problems with RaiseEvent
HTML:
      <div id="login" class="login">
        <div style="color: #5a72b8; height:21px; margin-top: 20px;">
          <label>Username</label><input type="text" name="username" tabindex="1"> <input type="image" src="http://mysite.com/sign_in.jpg" tabindex="4" alt="Sign In" title="Sign In" width="80" height="21" style="margin-left: 4px; vertical-align: bottom"/></div>

        <div style="color: #bfd4e7; height:21px;">
			    <label>Password</label><input type="password" name="password" tabindex="2" style="margin-left: 2px"> <input type="checkbox" name="autologin" tabindex="3" style="padding-top: 2px;"/><small>Remember Me</small><br>
        </div>
        <a id="login" class="forgot" href="/account/sendpass" title="Forgot your username/password?">Forgot your login?</a>
        <input type="hidden" name="submit" value="Login" />
        <input type="hidden" name="sid" value="0d77d49b7c5f6468d768a2a1f7fb6b76" />
        <input type="hidden" name="redirect" value="http://www.mysite.com/" />
      </div>
    </div>
After trying various things...

Me.wb.Document.All("sign in").RaiseEvent("click")
Error: Object reference not set to an instance of an object.

Me.wb.Document.All("Submit").RaiseEvent("click")
Error: Value does not fall within the expected range.


Me.wb.Document.Forms("sign in").InvokeMember("click")
Error:Object reference not set to an instance of an object.

Me.wb.Document.Forms("submit").InvokeMember("click")
Error: Object reference not set to an instance of an object



The one in bold, did I raise the wrong event? or still wrong ID?
Or something else I'm not seeing?

(Im trying to click the image, which submits the data ..but not really sure what its ID is... is it its imagename.jpg?)

Thanks for your time
 
Last edited:
"click" is not an event of the DOM element, it's a method, "onclick" is an event. Try raise "onclick" event and .InvokeMember("click") method.

It doesn't look like the submit image button have neither ID or Name set, so you could find it with perhaps GetElementsByTagName or index. I don't see a "form" tag defined there, so you won't have document.forms available, but if there is just you didn't post it you should also be able to do this:
VB.NET:
wb.Document.Forms(0).InvokeMember("submit")
 
Back
Top