Link to home
Start Free TrialLog in
Avatar of sgaggerj
sgaggerjFlag for United States of America

asked on

VB.Net setting input fields on web page

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?
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

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
Avatar of sgaggerj

ASKER

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.


ASKER CERTIFIED SOLUTION
Avatar of Wayne Taylor (webtubbs)
Wayne Taylor (webtubbs)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I'll try that then when I get back in the office.  My fault I didn't look closer at the API.
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?
Nope, no idea there I'm sorry.
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.
webtubbs should get all 500 points.  I didn't mean to close it w/ no points.
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
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.
@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.