Solved

VB.Net setting input fields on web page

Posted on 2010-09-02
12
566 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Advice in Xamarin 21 80
Variable Event ? 3 29
Sql server insert 13 32
VB.net Progress Bar - Maximum Value too large 2 12
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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