?
Solved

VB.Net setting input fields on web page

Posted on 2010-09-02
12
Medium Priority
?
573 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
11 Comments
 
LVL 48

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 48

Accepted Solution

by:
Wayne Taylor (webtubbs) earned 2000 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
 
LVL 48

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 48

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 48

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
Loops Section Overview
Suggested Courses

862 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