Solved

VB.Net setting input fields on web page

Posted on 2010-09-02
12
568 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
vb.net winforms sizing/resolution? 4 57
Iteration Help (Asp.net VB) 5 37
ASP.NET (VB) return a record 2 52
System.net.Sockets Error 5 40
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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…

730 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