Solved

VB.Net setting input fields on web page

Posted on 2010-09-02
12
564 Views
Last Modified: 2012-05-10
Hi Experts,

i'm trying to interact with a web-page through my app using vb.net / vs2008.
i have a webbrowser control on my form and the page i need to interact with is loaded there (in this case, http://www.fedex.com/us/)

I am trying to set the username and password fields, but cannot find how to access them.
i would also need to click the login button, or trigger the submit.

i have tried various iterations of

WebBrowser1.Document.GetElementByID and .GetElementByTagName to no avail.

Help?
0
Comment
Question by:sgaggerj
  • 6
  • 5
12 Comments
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33591437
This works fine for me.

        WebBrowser1.Document.GetElementById("username").InnerText = "username"
        WebBrowser1.Document.GetElementById("password").InnerText = "password"

Where are you trying to set these fields? Could it be that the page has not fully loaded?

Wayne
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33591471
i'm running this code in the Navigated event handler of WebBrowser1 (which should mean it's fully loaded right?)


i had tried using

Dim u as HtmlElement = WebBrowser1.Document.GetElementById("username")

and was always coming up with 'nothing' as the value of u. (still am)

my IE is IE8, but i don't think that should matter.


0
 
LVL 47

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 500 total points
ID: 33591523
The Navigated event occurs when the WebBrowser control has navigated to a new location and begun loading. What you need is the DocumentCompleted event.

Wayne
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33591623
I'll try that then when I get back in the office.  My fault I didn't look closer at the API.
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33596111
Yep, that was what I was doing wrong.

Any suggestions on "clicking"

i've tried

WebBrowser1.Document.GetElementById("login").InvokeMember("click")
and
WebBrowser1.Document.GetElementById("logonForm").invokeMember("submit")
and
WebBrowser1.Document.Forms.Item("logonForm").InvokeMember("submit")

the "click" doesn't do anything
the "submit" both give a 405 error.

any suggestions?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33596357
Nope, no idea there I'm sorry.
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33596487
Ok, seems I got it working using an idea from

http://www.vbforums.com/showthread.php?p=2618114#post2618114

        For Each ele As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
            If ele.Name = "login" Then
                ele.InvokeMember("click")
            End If
        Next

now, why the above didn't work i have no idea.
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33596529
webtubbs should get all 500 points.  I didn't mean to close it w/ no points.
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33596533
Ahh, there's actually 2 elements named "login". The first one (which was returned with the single line code) is actually a DIV, so invoking the click on it would do nothing.

Wayne
0
 
LVL 47

Expert Comment

by:Wayne Taylor (webtubbs)
ID: 33596554
Sorry, but I have to object to how you are closing this question. I answered the original question as asked. The clicking problem was a subsequent query and not mentioned until after your original question was solved.
0
 
LVL 1

Author Comment

by:sgaggerj
ID: 33600472
@WallyMod

Thank you

@webtubbs

Sorry about that, i posted right away that you should get all 500 points, and am glad to see you did.

(the clicking was part of the original question though)

Thanks again for your help.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
The purpose of this video is to demonstrate how to set up the WordPress backend so that each page automatically generates a Mailchimp signup form in the sidebar. This will be demonstrated using a Windows 8 PC. Tools Used are Photoshop, Awesome…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now