# VBForums CodeBank > CodeBank - Visual Basic .NET >  Manipulate/Change/Form Fill data in webpages using the Webbrowser control

## kleinma

All the time I see people asking how to autofill in forms on webpages or how to click a button in a webpage that is hosted in the webbrowser control, via VB code.

It is really not all that difficult, once you get around the casting of types to the correct kind when using the COM reference.

This example project highlights the following manipulations (as well as opening the door to manipulate just about anything on a webpage that is possible)

* Getting a value of an HTML input element
* Setting a value of a HTML input element
* Getting a value of an HTML text area
* Setting a value of a HTML text area
* Set HTML radio buttons selected or not
* Click an HTML button
* Submit an HTML Form
* Get the sources for all images in HTML document
* Get and display all the links in the HTML document
* Alter non form elements (like changing the color of a DIV tag)
* Getting values from an HTML Select element (value and selected index) 
* Display page HTML source
* Run a javascript that is in the HTML Page
* click a checkbox in an HTML form
* Print the current page (with printer selection dialog)
* *Added 8/24/2006 - Highlight webpage text via code*

This specific example code is done using

Visual Studio 2005 (VB.NET)
However I use the COM WB Control, not the built in .NET 2.0 WB Control (because its functionality is rather limited)
I also use a reference to the MSHTML scripting engine, which is what allows you to parse a webpage into all its elements so you can manipulate them.


Please let me know if you have any questions/comments/suggestions.

I can add more functionality examples if someone can think of one....

----------


## Mc_F

I need something like that for VS 2003. As much as I like VS, I hate the way MS uses upward compatibility. Basically all I want to do is learn how to programmatically fill in fields on a webpage from within my application.

Here I am attempting a login attempt on a website. (username text box = edit_username)
So far:


VB Code:
Dim CookieContainer As New CookieContainer
Dim strPost As String = "edit_username=my_username&edit_password=my_password" 
Dim myWriter As StreamWriter
Dim objRequest As HttpWebRequest = CType(WebRequest.Create(uiURL.Text), HttpWebRequest)
Dim cookies As CookieContainer = New CookieContainer
  'objRequest.AllowWriteStreamBuffering = True
   objRequest.Method = "POST"
   objRequest.ContentType = "application/x-www-form-urlencoded"
   objRequest.CookieContainer = cookies
    myWriter = New StreamWriter(objRequest.GetRequestStream())
   myWriter.Write(strPost)
   myWriter.Close()
 Dim objResponse As HttpWebResponse = CType(objRequest.GetResponse(), HttpWebResponse)
Dim str As StreamReader
   str = New StreamReader(objResponse.GetResponseStream)
   uiInfo.Text = str.ReadToEnd
   myWriter.Close()
    objRequest.GetResponse().Close()

Thanks.

----------


## kleinma

well my example is using the webbrowser control, which displays the HTML page rendered the same was the IE browser does.

What it looks like you are doing, is a more "behind the scenes" approach, by posting form data to a URL, and getting the resulting response.

Is this what you want? or would you rather use the webbrowser control and auto fill the fields and submit the form?

----------


## Mc_F

Lets say I have a text box on a form that I put the HTML source into after issuing an HTTPWebRequest and receiving a response.

Below that I have a WebBrowser control that shows the page.

The textbox with the HTML  is not the same as the WebBrowser. 

In other words, the HTML is a login page whereas the WebBrowser shows what the HTML should be after log in.





> Is this what you want?


 YES

----------


## kleinma

why not just automate the login itself by autofilling the fields right in the browser control, and then submitting the form. that way you don't have to use webrequests at all.

Check out this example I had done for someone a while ago in this post
http://www.vbforums.com/showthread.p...ght=webbrowser
it is done in .NET 2003, so you can open it and check it out.

----------


## Mc_F

WebBrowser.Document.forms.item(, 0).elements("field1").value = "myvalue"

Why doesn't anything after the Document object get acknowledged?
It won't work for me this way. Could you explain?

----------


## kleinma

do you mean why doesn't intellisense come up? Its because it uses late binding since the .NET framework sees everything past the webbrowser itself as a plain object (including the document)

to get around this, and get intellisense for all the elements of the HTML form, you would have to add a reference to MSHTML which is the .NET wrapper DLL around microsofts HTML parsing engine. Then you can cast the webbrowser.document to a MSHTML.HTMLDocument and gain access to its stuff through there. This is what I did in the code bank example above, but its for 2005 and not 2003 (although it would work just the same in 2003)

----------


## Mc_F

VB Code:
'Cast the web browser document
         With DirectCast(wb.Document, mshtml.HTMLDocument)
            .forms.item(, 0) 'as far is it goes with intellisense.
         End With

the name of my field I want to access is "edit_username" and I want to put the value "guest" in it.

Thanks.

----------


## kleinma

ahh... well all you SHOULD need to do is this:

even though intellisense doesn't work for it.. the code will still run

WebBrowser.Document.forms.item(,0).elements("edit_username").value = "guest"

This code basically translates as 

In the WebBrowser's Document, I want the First Form (which is index 0, hence the forms.item(,0) part) and I want the element in this form called "edit_username", and I want to make its value "guest"

If you want to give me the URL you are trying to autofill, I can modify the example code to reflect that site.

----------


## Mc_F

I see how that works, but this is broken down like this, so you may help me with a solution:

go here: http://bright-shadows.net/challenges...ted/tryout.php
 there is the login form

 once logged in, there will be text on the screen and if you 'view source' there are no tags or anything, just the text that you see on the screen. This text is what I want to put in my text box.

So if at all possible, I would like to automate the process by passing login info to the page and getting the text in my text box. Is there a way to determine if the login page is showing or just the text after the automation process?

Thanks.

----------


## kleinma

well I would need a login/password.

I totally understand if you don't want me to use yours, I can only tell you that I wouldn't use it for anything (I don't even know what bright shadows is)

If you want to PM me with your login info, I will see if I can make you a sample that works. You can then change your password for security reasons after that.

If you don't want to give me the login info, I totally understand, however I am not going to make myself an account just to make sample code for you (no offense or anything.. its just a bit much  :Wink:  )

----------


## kleinma

I got your PM... I get something like 

The "text" is: '*some random text*'

when I log in.. is that what should be displayed?

----------


## Mc_F

Exactly. I just want to auto login by code and retrieve that text.

----------


## kleinma

ok... ill be back

----------


## Mc_F

Depending on what you come up with I would really like to use something along the lines of: 
using the httpwebrequest / httpwebresponse along with using the credentials property.
Below sends the user/password.

VB Code:
' Create an empty instance of the NetworkCredential class.
         Dim myCredentials As New NetworkCredential("", "", "")
         'myCredentials.Domain = domain
         myCredentials.UserName = "my_username"
         myCredentials.Password = "my_password"
          ' Create a WebRequest with the specified URL. 
         Dim myWebRequest As WebRequest = WebRequest.Create(uiURL.Text)
         myWebRequest.Credentials = myCredentials
         uiInfo.Text = ("User Credentials: " & vbcrlf & "Username=" & myCredentials.UserName & "password=" & myCredentials.Password)
          ' Send the request and wait for a response.
         Dim myWebResponse As WebResponse = myWebRequest.GetResponse()
          '=================================================
         Dim sr As StreamReader
         sr = New StreamReader(myWebResponse.GetResponseStream)
         uiInfo.Text += str.ReadToEnd 'not getting the desired HTML
         ' Release the resources of the response object.
         myWebResponse.Close()

thanks for your help.

----------


## khuntballa

Hi I am a VB noob, but I am trying to learn and I have been beating my head over the past few days trying to come up with a solution for my problem. 

I am making a web browser utility for a text based game that does a few things.

1. It logs into a a site and submits- Finally figured that out when I realized 2005 didn't have form.submit function I had to use invokememeber("submit")

2. It goes to a ranking page submitted by an upper and lower bounds in increments of 50 and retrieves the links of players there.  The players links are in the form of stats.php?id=sixdigitnumbergoeshere.

3.  It will go one by one and send recruiting messages to the existing players and will have to submit a form again.  In order to submit that form one will have to type in a 6 letter captcha that should be displayed on the page.


All that I am worrying about for now is the 2nd part.  I have tried many things , even tried using your GetCurrentwebdoc function and my latest attempt at grabbing links was this:


VB Code:
Dim pageSource As String
        pageSource = Webbrowser1.Document.All("stats.php?id=").InnerHtml

again the idea from these forums because I am just desperate at this point.

If any help could be provided it would be much appreciated.  Thank you.


Kevin

----------


## andrewteg

Just wanted to say thanks for this. I have a website that needs certain parts on a CD for distribution and this has come in very valuable! I appreciate the effort and was happily surprised I could get it working on my own just based on your examples even though I haven't used VB regularly in 6+ years!

----------


## kleinma

> Just wanted to say thanks for this. I have a website that needs certain parts on a CD for distribution and this has come in very valuable! I appreciate the effort and was happily surprised I could get it working on my own just based on your examples even though I haven't used VB regularly in 6+ years!


Glad to hear it helped you out.   :wave:

----------


## andrewteg

kleinma (or others),

Has anyone had any success in going the other way? By this I mean clicking on something in a Webrowser control (like a link or button) and getting that to run VB code?

This stuff is great for clicking a VB object and manipulating a browser but I was just curious as this would open up a whole new realm of fun and usefulness I think  :Smilie: 

Thanks,
Andrew

----------


## kleinma

Yeah you can attach events to specific elements... I know I saw a MSKB article about hooking up the client side events of the DOM to fire in a VB app. I will see if I can find it

----------


## mduclon

This is a great example. I have a question, I have a form using the Com WebBrowser like this. I use it to fill in and submit a form but on submit I go to a page and get a popup javascript messagebox. I need to close that so I can continue on. 
Does anyone know how I can make it close or click the ok button, in code?

MD

----------


## matosguide

It is possible to get links that are inside a frame ?
How can I achieve that ?

Thanks in advance!!

----------


## kleinma

> This is a great example. I have a question, I have a form using the Com WebBrowser like this. I use it to fill in and submit a form but on submit I go to a page and get a popup javascript messagebox. I need to close that so I can continue on. 
> Does anyone know how I can make it close or click the ok button, in code?
> 
> MD


Not that I can think of at the moment, but if I come up with something I will post it.

----------


## kleinma

> It is possible to get links that are inside a frame ?
> How can I achieve that ?
> 
> Thanks in advance!!


Yes I am sure you can easily do this. You would just need to access the frame itself, and then you can loop its links. Do you have a specific URL you are trying to work with?

----------


## matosguide

I can't post the page I'm trying to open.... sorry.
The page have two frames (head & main) and the source are two cgi scripts.
I could go directely to the one I need, but the problem is that it updates the other frame...

I tried to use framecollection but with no sucess... Can you help me with this ?

Thanks in advance

Best regards

----------


## edwardm

Hi, 

This was realy good reading, but how can I fill a site with more than one form (one of the forms that is). How can I find out the syntax in the Document.Forms.Item(, 0).elements, I'm refering to the "0" which I guess is the value that trows my code off(?).

Edward.

----------


## ldadams

Do you know of a way to auto download a file using your browser?

Cheers
Luke

----------


## kleinma

If you look at my signature, you will see an example code for downloading a file from the web with progress...

All you do is pass the URL to it and it can download any file.

----------


## ldadams

Sorry if this is a repeat post.

I have already tried something similar to that.  The problem I am having is, I have to script my way past a logon screen to get to the page where I want to download from.  So I thought I could just create a VBScript that opens IE logs me on and then runs my exe.  Well that doesnt quite work.  The problem is that logon is per session.  And since that utility opens a new response it wants me to logon again.  Is there anyway to get the response straight from the WebBrowser Control? Or do you know of a way to fire the Click event of the Save/Open Dialog box?  Thanks for you help!!

Cheers,
Luke

----------


## kleinma

once you get past the logon page, is there a link you click to download the file?

----------


## ldadams

No not currently.  Its a perl function that I pass a date to in the URL.  So the URL I actually download the file from is something like: https://ecf.flnb.uscourts.gov/cgi-bi....pl?09/26/2006

If the date exisits in the URL it gives me back a zip.  If not page requires user input.  Even if there was a link how would I download without creating a new Response.  Is there a way to access the response of the webbrowser control?Hope this makes sense.

Cheers,
Luke

----------


## kleinma

it kind of makes sense to me, however it sounds like the type of thing I would really need to mess around with to get working. If you want to provide me with the actual URL and give me enough info to get in and test with it, I can see if I can do something.

----------


## ldadams

I really wish I could but I cant give out that information, its out of my hands.  I will play with it and see what I can come up with.  If you think of anything please share  :Smilie: 

Cheers,
Luke

----------


## kleinma

Sure.. if you make any progress, but get stuck somewhere let me know too, I will try to help out where possible

----------


## Nouvelian

Kleinma, you seem incredibly helpful. Many thanks for the efforts... I've downloaded your .zip file(s) on filling forms on .html documents, but I'm using VB 6... you wouldn't have a similar .zip for VB 6 users would you?

----------


## kleinma

Sorry.

I have written code in VB6 using the WB control before and done some page manipulations, however that was all commercial code, and not really in any type of code sample that I could provide. 

I don't code in VB6 anymore unless I have to for a project, so all my code is now either .NET 1.1, or .NET 2.0

----------


## Nouvelian

Many thanks anyway.

----------


## slice

btw this same code can be used with visual basic 6.0 ?

----------


## kleinma

Many of the concepts can be used in VB6, however the specific .NET code will not be a simple copy/paste into VB6.

If you know .NET and VB6 you could probably easily port this code over to VB6

If I ever have some free time, maybe I will try, since you are the second person to ask in just a few days, but for now its really just .NET 2003/2005

----------


## slice

thanks .. actually i have not vs.net installed so its problem for me not for you to convert it into vb6.
i know its not big change code.  :Smilie:

----------


## Massino

Hi Kleinma!

Believe it or not I have the same problem...
But I couldn't resolve mine by this.
I'd like to autofill the two login fields(username,password) and submit it automatically,
but the above codes doesn't work somehow.
Would you try it with this url for me as well? : http://www.lemuria.hu
Thanks in advance, Massi.

----------


## kleinma

What code did you try?

----------


## Massino

Well I already figured out the first part,
I could succesfully fill the username and the password
elements with this code :
WebBrowser1.Document.GetElementsByTagName("Input").Item(0).SetAttribute("Value", "Username")
WebBrowser1.Document.GetElementsByTagName("Input").Item(1).SetAttribute("Value", "Password")
Now the next thing should be to figure it out how to "click" the submit button to submit the form with the new attributes. Cause VB says : i cannot raise the click event directly, only by the raiseevent handler...
And I forgot to tell ya, I'm using Visual Studio 2005

----------


## kleinma

My example code shows how to click a button via code.

----------


## Massino

It says : Error	1	'submit' is not a member of 'System.Windows.Forms.HtmlElement'.	D:\_Temporary_\Visual Basic Programs\Lemuria\Lemuria\Lemuria\Form1.vb	11	9	Lemuria
I tried the click and the submit as well. 
Sometimes it says : Value does not fall within the expected range.
Now I'm stucked.

----------


## Massino

Thank God I've managed it finally.
Here's the full code what works for me :
Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Document.GetElementsByTagName("Input").Item(0).SetAttribute("Value", "Username")
        WebBrowser1.Document.GetElementsByTagName("Input").Item(1).SetAttribute("Value", "Password")
        WebBrowser1.Document.GetElementsByTagName("Input").Item(2).InvokeMember("Click")
    End Sub
End Class

----------


## kleinma

You probably aren't using my example code, because that uses the MSHTML library and you can directly access members and click buttons and such using that. It looks like you are using the standard 2.0 Webbrowser control, which my example code doesn't use.

----------


## Massino

If you mean I didn't add the reference to mshtml, I did.

----------


## kleinma

No I didn't mean you didn't add the reference, I just mean it doesn't look (from the code you posted) that you actually used MSHTML at all.

----------


## Winla

Hi kleinma
I download your code and it works great! thx
Now I have two related questions for a web site like 
www.whitepages.com:

1)for this submit click code 


VB Code:
DirectCast(GetCurrentWebForm.item("cmdSubmitMe", 0), 
mshtml.HTMLButtonElement).click()

to work , you have to find the button id, but for above web site, the submit
 buttons has no id to refer to. How to go around this?

2)I want to extract all the names and address, phone numbers from
 searching page into a datagridview control. What is the best way to do it?
 I am thinking of regex pattern match, but for this web site, the returned
 source code is too complicated to handle.

Thanks

----------


## kleinma

You could just grab the forms themselves, and call the submit method of the form, instead of using the click method of the button.

Regex or just a complex parsing routine may be your best bet... you could probably trim down the returned HTML source and just find the table or whatever that all the data you want to parse is located in, and just parse that part of the HTML.

----------


## Winla

thx for reply. Could you be more specific about how to parse and trim down the returned HTML source to the table I need. A basic sample code would be very helpful.   I know you can get all links by using mshtml as you suggested in  other posts but it is more complicated here for my purpose. btw, I am using VS 2005.

----------


## ImaVBNoob

How would this work with VB 6.0?

----------


## FlyingBear

> Please let me know if you have any questions/comments/suggestions.
> 
> I can add more functionality examples if someone can think of one....


Is it possible to manipulate a file uploader? the html is:
==========================
<div>
<input type="file" name="uploadfile">
</div>
==========================

just like the one for 'manage attachment'. 

Can I set the file name directly from program instead of click the 'file' button? I tried to change its value, outerhtml, etc... all seem don't work.

thanks


bear

----------


## kleinma

I would imagine you would simply just set the "value" attribute of the input tag to whatever file name you wanted.

Follow the example code for auto filling a textbox, but apply it to an input file box instead... it should work the same exact way.

----------


## FlyingBear

no, I tried it. If I just set the value in program, it will reset the uploader, which means the file textbox becomes blank. I use .net web browser, did not try the activex browser yet. If I input the file name, then in debug, I can see the value of the uploader is changed to the file name.


thanks


bear

----------


## Passgad

Hi kleinma,

I found great info in this post but you didn't answer how to access a frame with the webbrowser.

I have a page with 2 frames and I want the value of a textbox (txtVersion) in the second frame.

Thanks,
Pass

----------


## kleinma

do you have a URL I can test with?

----------


## Passgad

Sorry, it's not online and it uses the windows authentication...

But basically, I have an application like yours with the webbrowser control who refers the a basic html page with 2 frames in it. Each frame refers to a simple aspx page. The second page contains the txtVersion that I need the value to set a textbox in my application.

Thanks,
Pass

----------


## Passgad

I tried this :


VB Code:
Dim document As mshtml.HTMLDocument = DirectCast(WebBrowser1.Document, mshtml.HTMLDocument)
Dim form As mshtml.HTMLFormElement = DirectCast(document.forms.item(0), mshtml.HTMLFormElement)
Dim Version As String = DirectCast(form.item("txtVersion"), mshtml.HTMLInputElement).value
 MsgBox("Version : " & Version)

I get this error :

System.NullReferenceException: Object reference not set to an instance of an object.

For now, the page doesn't contain a frameset. I wanted to try to access the textbox in the form first...

Also, will all this will work in VB.Net 2003 ?

----------


## kleinma

Yes all code should work in 2003, as the example uses the COM webbrowser, not the windows forms webbrowser which was introduced in 2005.

The windows forms webbrowser is basically a wrapper around the COM interface, run all in managed code, however it has many short comings and missing features (I assume for full managed code compatibility). For example (just one of many) the 2.0 webbrowser doesn't have a navigate_error event, but the COM one does.

As far as your error, I am not sure why you are getting it, as it could be related to the specific HTML page you are parsing the data out of. If you run the example code, you will see that it does infact work to get text from a textbox in a webpage.

----------


## Passgad

Ok, I found a way to get the value a the txtVersion when the page is not in a frameset :


VB Code:
Private Sub AxWebBrowser1_DownloadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWebBrowser1.DownloadComplete
    Dim document As mshtml.HTMLDocument = DirectCast(AxWebBrowser1.Document, mshtml.HTMLDocument)
    Dim form As mshtml.HTMLFormElement = DirectCast(document.forms.item(0), mshtml.HTMLFormElement)
    Dim Version As String = DirectCast(form.item("txtVersion"), mshtml.HTMLInputElement).value
    MsgBox("Version : " & Version)
End Sub

Do you have an idea when the page is in the second frame of a frameset ?

This doesn't work :


VB Code:
Private Sub AxWebBrowser1_DownloadComplete(ByVal sender As Object, ByVal e As System.EventArgs) Handles AxWebBrowser1.DownloadComplete
    Dim document As mshtml.HTMLDocument = DirectCast(AxWebBrowser1.Document, mshtml.HTMLDocument)
    Dim frame1 As mshtml.HTMLFrameElement = DirectCast(document.frames.item(0), mshtml.HTMLFrameElement)
    Dim frame2 As mshtml.HTMLFrameElement = DirectCast(document.frames.item(1), mshtml.HTMLFrameElement)
    Dim form As mshtml.HTMLFormElement = DirectCast(frame2.forms.item(0), mshtml.HTMLFormElement)
    Dim Version As String = DirectCast(form.item("txtVersion"), mshtml.HTMLInputElement).value
    MsgBox("Version : " & Version)
End Sub

----------


## kleinma

If you want to make me a little dinky 2 frame HTML page, I will be more than happy to use it here to write some code to grad the data out of it.

The issue MAY be in the fact that inside each frame might be considered a document, so you would have to grad the document of the frame, then the form from the document. (and then the textbox element)

If you want to upload me a sample page to use for analysis, I can confirm that.

----------


## Passgad

I will try to PM the source code tonight or tomorrow, but please, do not share... Just take what you need.

I also found something interresting; you cannot grab value of a textbox with property visible = false...

Thanks,
Pass

----------


## kleinma

do you mean an ASP.NET textbox with visible set to false? If so, that is because ASP.NET simply doesn't even render HTML for it when its not visible.

If you are talking about a regular <input type=text> tag, then visible isn't a valid HTML property of the tag anyway.

Also, I don't need your whole source, I just need a sample HTML page with frames in it, so I can test grabbing data in the frames. If you provide one, I will take a look at it and try to provide an answer.

----------


## mailtosubbu7

Hello sir,

I am new member to this forum.
I have one doubt in vb.net 2005.
How to set the file upload element value using web browser control?.
Thank you for advance.

Regards,
Subu

----------


## mailtosubbu7

I am tried using setattribute and other command in .net 2005 but i can set the value of file upload element but i am trying send key to set the value but this is very slow.
There is anyother solution?.

----------


## nnolte

I have a newbie question that hopefully the experts here can answer quickly without me being too much of a nuisance.  In the past, I have created simple apps to fill in username and password fields using the webbrowser control in VB.

However, now I am trying to get past a page that implements frames, one of which contains the username and password fields in question.  For some reason the method I have used in the past (with varying field names, obviously), namely:

With wWeb.Document
            .All("username").Value = "loginid"
            .All("password").Value = "pword"
            .getElementById("Submit").Click
End With

doesn't work with frames.  The web page in question will not let me navigate just to the frame that I need (probably for security reasons).

My questions are:

1. Can anyone point me to where I can get some documentation for what properties and methods can be used under the Document property (i.e. some documentation on WebBrowser.Document._GetElementById_ or WebBrowser.Document._GetElementByName_ or WebBrowser.Document._Frames(x)_ or other properties and methods).  I can't help but think if I could get to that information I could figure it out.

2. Can anyone figure out how I should modify the above code to satisfy this web page --> https://sportal.uspto.gov/authentica...rLocalEPF.html

I would prefer to use VB6 but also have access to VB.NET 2005.

Thanks for any help you can render.

----------


## kleinma

I am not aware of any easy way to auto fill content within frames.

I also didn't find anything that looked promising in my searches.

If I do figure out a way to manipulate content in frames, I will update this example code accordingly  :Wink:

----------


## coheed

Ok... this should be easy, but I'm having  a terrible time...

kleinma, I've looked over your sample and still can't get this to work:

All I'm trying to do is fill in the info on the paypal website and log in. The email field is named "login_email", the password field is "login_password", and the submit button is named "submit.x"

I've scrapped all of my repeated attempts, because I haven't been able to get anything to work. 

I've ended up with this, even though I know it's not exactly how you coded your  sample, I ended up straying away because I couldn't get yours to work.



```
        If IsBrowserBusy(WebBrowser1) = False Then
            Dim HTML As HtmlDocument
            Dim HTMLS As mshtml.HTMLInputButtonElement
            HTML = WebBrowser1.Document
            HTML.All.Item("login_email").InnerText = "***"
            HTML.All.Item("login_password").InnerText = "*****"
            HTML.All.Item("submit").Click()
            For Each HTMLS In WebBrowser1.Document.GetElementsByTagName("input")
                If HTMLS.type = "submit" And HTMLS.value = "Log In" Then
                    HTMLS.click()
                    Exit For
                End If
            Next


        End If
```

IsBrowserBusy is just a function I made to return whether or not the browser is busy. With this code, the textboxes were filled in, but I can't get it to submit, before even compiling i get this error:

"Error	1	'Public Event Click(sender As Object, e As System.Windows.Forms.HtmlElementEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event."

Ugh, this is frustrating! Hopefully you have some time to lend a hand-

----------


## kleinma

Just use the 2005 webbrowser, and use the InvokeMember() method

I have attached example code.

I actually plan on rewriting the original example in this thread using the 2005 webbrowser (even though it still does have some limitations that the COM browser doesn't)

however it also does have some advantages.

So anyway take a look at the attached zip file, you will see its only a few lines of code to do a paypal auto login.

----------


## coheed

Perfect, you're the man!

Any clue where I can find a good writeup on the 2005 web browser?

----------


## kleinma

well its a control that is actually a built in part of the .NET 2.o framework, so a good starting place would be to go through the MSDN help documentation on it. It will list all the properties, methods, events, etc...

----------


## ggodwin

Sorry for the mistake. :wave:

----------


## kleinma

Sorry but you are using VB6 and IE automation,  and all this example code is done with VB.NET, and ActiveX/.NET webbrowser controls.

----------


## GP_Agrestic

Hi fellows,
              i am trying to do a similar stuff and i am very much successful as of yet. I am building a desktop application in C# which will submit form by HttpWebRequest and HttpWebResponse in addition to other functionalities. i came across a problem when i was trying to submit form on a ASP.Net site as it wont yield the page after login. One reason a friend told me was that i was not incorporating ViewState value in the data being sent. Now as i am building a desktop application and i need UrlEncode function of HttpUtility class for converting viewstate value into base64 equivalent(reason being that this representation caters for escape sequences). I cant access this class in a desktop application.
 Can anyone tell me that am i going on right track and if yes what else i need to do.
ur assistance will be of great help to me.

----------


## ArmchairAthlete

I'm using VS2005 and VB.NET, .NET framework 2.0. 

I've read most of this thread... in hopes to be able to "click" on HtmlElements with a WebBrowser, without luck. The issue is I don't want to do this in a windows form app.

I've tried both the InvokeMember("click") method and the reflections/DomElement, which work fine if the browser is on a Windows Form but just hang and don't do anything in my ASP.NET application (where I instantiate the browser myself). 

I can get the browser to navigate to pages however. I have to be running in a separate thread with ApartmentState STA. 

The AxSHDocVw.AxWebBrowser() ends up throwing this out trying to navigate:
*An unhandled exception of type 'System.Windows.Forms.AxHost.InvalidActiveXStateException' occurred in AxInterop.SHDocVw.DLL
*

----------


## kleinma

wait, so what exactly are you trying to do? Invoke your own clicks in an ASP.NET application?

----------


## ArmchairAthlete

Yea that's what I need to do. I wouldn't need the WebBrowser object except for javascript use in some pages I'll need to crawl. The dependence on a web browser object doesn't lend itself well to the parallel nature of crawling, but usually httpwebrequest/response is what I'll use. 

We have an old VB6 winform app that is able to do this fine, but in a winform. I'd like to have a sort of independent library that I can choose to use wherever, (asp.net, cmd line, etc). Wanted to use the web browser despite not having one actually visible as it normally would be, and still be able to simulate clicks.

----------


## kleinma

why not just use a winform and put the webbrowser off screen?

----------


## ArmchairAthlete

I want to be able to do this from within an ASP.NET application. 

Now I'm down to just wondering if I should have the web app start off an exe webform app and communicate with it somehow... probably not worth it.  :Alien Frog:  

Is there no other way besides these WebBrowser objects to deal with executing javascript that does whatever and eventually takes me to another page? Without writing a javascript interpreter or something, hah.

----------


## ArmchairAthlete

Nice, I can do .Navigate and have the URL string just be the javascript in the link instead (with the .NET System.Windows.Forms.WebBrowser wrapper). 

Now to get this to work with buttons... some pages have onclick javascript that goes off, then expect the normal button's form submit on click to happen afterwards it seems.

Edit: well, that works with some javascript and even some I make up to .click() something in the DOM, but hangs with other js like described above.

----------


## Gibbo_Gibbo

> What code did you try?


I am a newbie to VB.Net, I have spent many hours researching the internet for info in reference to auto logon. This thread is the best thread I have seen yet. But your attitude towards inquiries is out standing. You are constantly offering to write code on behalf of the inquirer. It show that you are a person of great character. I AM AMAZED. I am using 2005 VB Express, unfortunately I am unable to get your webpage manipulation code to work. Has 21 errors when opening. I would love to see it in action. Any recommendations apart from purchasing VS 2005. Thanks in advance... :Thumb:   :Smilie:

----------


## kleinma

You should NOT need a pay version of Visual Studio to get the code to work. However perhaps if you can list (some) of the errors, I could point you in the right direction to get it fixed.

----------


## Gibbo_Gibbo

as requested: 
All I can debug is that my Vb 2005 Express does not know "mshtml"
Looking fwd to your reply
Thanks //Gibbo   :Smilie:  

Discription					Line	Column
Error 1	Type 'mshtml.HTMLDocument' is not defined.	85	22	
Error 2	Type 'mshtml.IHTMLTxtRange' is not defined.	86	24	
Error 3	Type 'mshtml.IHTMLTxtRange' is not defined.	87	61	
Error 4	Type 'mshtml.HTMLDocument' is not defined.	99	44	
Error 5	Type 'mshtml.HTMLDocument' is not defined.	101	44	
Error 6	Type 'mshtml.HTMLFormElement' is not defined.	110	45	
Error 7	Type 'mshtml.HTMLFormElement' is not defined.	113	67	
Error 8	Type 'mshtml.HTMLInputElement' is not defined.	129	54	
Error 9	Type 'mshtml.HTMLInputElement' is not defined.	133	85	
Error 10	Type 'mshtml.HTMLTextAreaElement' is not defined. 138	55	
Error 11	Type 'mshtml.HTMLTextAreaElement' is not defined.142	86	
Error 12	Type 'mshtml.HTMLOptionButtonElement' is not defined 148  67	
Error 13	Type 'mshtml.HTMLOptionButtonElement' is not defined. 150 67	
Error 14	Type 'mshtml.HTMLButtonElement' is not defined. 156	61	
Error 15	Type 'mshtml.HTMLButtonElement' is not defined. 162	62	
Error 16	Type 'mshtml.HTMLAnchorElement' is not defined. 176	28	
Error 17	Type 'mshtml.HTMLDivElement' is not defined.	186	22	
Error 18	Type 'mshtml.HTMLImg' is not defined.		225	28	
Error 19	Type 'mshtml.HTMLImg' is not defined.		229	73	
Error 20	Type 'mshtml.HTMLSelectElement' is not defined. 242	28	
Error 21	Type 'mshtml.HTMLInputElement' is not defined.	 250	31	
Warning	22 The referenced component 'Microsoft.mshtml' could not be found.

----------


## kleinma

looks like the only problem is you don't have the needed microsoft.mshtml.dll file which is the parsing engine.

On my PC it is located at
C:\program files\microsoft.net\primary interop assemblies\Microsoft.mshtml.dll

Search your PC and see if you have it. If you find it, add a reference to it in the "Add Reference" dialog, and the errors will go away.

Let me know if you don't have it and I could probably upload it.

----------


## Gibbo_Gibbo

You hit the nail on the head. The file is missing, no where to be found on C:drive... you can e-mail to cgibbons@bigpond.com.au....thxs

----------


## kleinma

microsoft.mshtml.dll

Here you go. I will leave it available on that server for a little while until I know you have gotten it.

----------


## Gibbo_Gibbo

Thxs, I have download the file, file has been copied into the same location as yours. Problem persist. I have attempted to enter path in the "add reference" dialog as you have recommended. But it is not allowing me to enter the value. Any suggestionssorry for the inconvenience

----------


## Gibbo_Gibbo

sorry found the problem thxs. please ignore my last message

----------


## kleinma

Glad to hear you got it working.

----------


## Gibbo_Gibbo

I need to ask the biggest favour ever. I have been researching the web for the last 14 days for a specific script. It appears that you seem to know what your are talking about, thus you may have the answer I seek. Therefore I need your advice and/or direction.

Objective
1. Open a http and/or https website
2. Wait until the page has completely finish downloading (e.g. done) before keystrokes "username" then "TAB" then "password" then "TAB" then "Click".

Please note: 
1 The problem is that I move about and thus am connected to varying internet speeds. "Wait" and "sleep" commands are unstable. 
2. Other sessions of browsers are already open. Thus the keystroke must be directed to the specific browser window. 
3. Plus the individual characters in the "username" or "password" are echoing. Which brings me to the next problem but is related. Slow down the keystrokes, such that the next keystroke will not occur until the script receives a reply from server acknowledges the previous keystroke. Again wait and sleep are unstable.
4. Please note that use of cookies is not an option as the website that I access issue new cookies every time I log on. 

In summary
I need to slow the script down between WebPages and keystrokes. The script steps thru as it receives acknowledgements from server

Thankyou
//Gibbo  :Smilie:  

P.S. your programme is great  :Thumb:

----------


## kleinma

well are you planning on making a windows forms app in VB.NET that will host a webbrowser control? If so then this sounds easy to do. If you are actually trying to automate an external instance of internet explorer, then that will be more difficult. I know you used to be able to create external instances of IE and automate them, but I think support for that has dropped.

Anyway, so if you wanted to make a windows app that hosts the browser control (which is what my example code does) then here are a few key points to keep in mind:

When you navigate to a page, you need to wait for the DocumentCompleted event to fire. This event fires when the page has been fully loaded in the browser. Unlike the navigated event which fires as soon as a navigation has started.

You don't need to send tabs and keystrokes to the webpage when you use the methods shown in my example code. You simply access the pages DOM (document object model) and fill in the needed fields, and click the needed buttons/links.

The only one of your points I am not sure of is number 3? What do you mean by echoing? Does the page post back to the server on every keystroke entered? Is that why you need the wait?

----------


## Gibbo_Gibbo

I have created a form with buttons to activate individual scripts. Simply I have to log onto many different secure websites at the same time in order to perform different task as part of my employment. Remembering all my usernames and passwords, plus constantly logging on and off website is frustrating. Hence the Form I am creating. Eventually as my experience and knowledge improves. I would like to auto fill the from on these websites from a database, as a lot of my work is repetitive.

The echoing. The script only has "a" as a keystroke followed by a wait of 500ms before the next keystroke. But the username field may display multiple "a". But this problem does not seem to occur when I am connect to a high speed broadband.

If you are able to provide a basic code to which I can model from and/or improve it would be much appreciated

It is now 0200hrs here in Aussie, Thus I must get some shut eye

Thanks
//Gibbo

----------


## roiegat

Hi guys.  I've read throught this whole thread and I'm hoping you can help me.  What I'm trying to do is automate a batch load process we have for our case tracking system.  Basicily we have a website internal to our company that we go to and input the filename.  You then click submit and it's done.

So I downloaded the OP's webmanipulate program and got it work well.  But when I tried to use the code into my project, it didn't seem to work.  It kept getting a repeating error of sorts.  So I tried other methods mentioned on this page.  The only method I got to somewhat work is:

 Browser.Document.Forms(0).GetElementsByTagName("Input").Item(0).SetAttribute("Value", "test1")

The result of this is that it puts "test1" is put into a text box, but not the right one.  I tried adjusting the Item number but it didn't work.  I could only get it to put the text in the top text box (which is a search bar thats a standard part of our company's intranet).

So here's the html code for the page which I got permission to post with some editions:


```
 


<html>
    <head>
        <title>Merckury Batch Load Upload Page</title>
        <script type="text/javascript">			
        var portallastmod='3 Mar 2005'
        var portalcontact='xxxxx@xxxxx.com'
</script>
	
        <meta name="Language" content="English language" />
        <meta name="Sensitivity_class" content="Business confidential" />
	
        <script src="/scripts/wrapperadd.js" type="text/javascript"></script>
        <script src="/scripts/portaldefaults.js" type="text/javascript"></script>

        <link href="/merckury/styles/batchload.css" rel="stylesheet" type="text/css">
    </head>
 
    <body>

        <!-- This is the include for the header -->
        <script type="text/javascript">portalInsertHeader()</script>
		<!-- Begin Breadcrumb Strip -->
		<div class="portalbreadcrumb">
			<a href="http://my.merck.com/index.jsp?epi-content=myMerckRedirectType&amp;epi-process=home_redirect.jsp">myMerck home</a> &gt; 
			batch load cases
		</div>
		<!-- End Breadcrumb Strip -->
        <div id="pagecontent">

            <br/>
            <br/>

            <form name="fileUploadForm" method="post" action="/merckury/batchFileUploadRequest" ENCTYPE="multipart/form-data" >
            <table width='600' border='0' cellpadding="1" cellspacing="1" align="center" bgcolor="#666666">
				<tr>
					<th>
						Merckury Batch Load Upload Page    
					</th>
				</tr>
                <tr>
                    <td>
                        <table width="100%" cellpadding="5" cellspacing="0" border="0" bgcolor="white">
                            <tr>
                                <td>
                                
                                    <br/>
                                    File Name: <input type="file" name="file1" size="80" />
                                    <br/>
                                    <br/>
            
                                    <div align="center">
										<input type="submit" name="submitButton" value="Submit"/>
									</div>

                                </td>
                            </tr>
                            <tr>
                                <td>
                                
                                    <a href="BatchLoad.xls">Get the batch load spreadsheet</a>

                                </td>
                            </tr>
						</table>
                    </td>
                </tr>
            </table>
            </form>
            <table width='600' border='0' cellpadding="1" cellspacing="1" align="center" bgcolor="#666666">
				<tr>
					<th>
						Look up ID Values    
					</th>
				</tr>
                <tr>
                    <td>
                        <table width="100%" cellpadding="5" cellspacing="0" border="0" bgcolor="white">
							<tr>
								<td>
								&nbsp;&nbsp;<a href="/merckury/batchIdLookup?lookuptype=0">Product IDs</a><br>
								&nbsp;&nbsp;<a href="/merckury/batchIdLookup?lookuptype=1">Category / Specialty Type / Detail IDs</a><br>
								&nbsp;&nbsp;<a href="/merckury/batchIdLookup?lookuptype=4">Provider Group IDs</a><br>
								&nbsp;&nbsp;<a href="/merckury/batchIdLookup?lookuptype=5">Attribute IDs</a><br>
								<br>

								</td>
                            </tr>

						</table>
                    </td>
                </tr>
            </table>



        </div>
        <script type="text/javascript">portalInsertFooter()</script>

    </body>
</html>
```

As I said before I'm justing trying to input the filename (which is standard) and then click submit.  My project has a browser in it called "browser" that navigates to the website when the form is loaded"

Also, for future refrence - is there a way to program a scan function to scan a website and display what the item numbers are?  So basiclly after going to a website I would hit a "scan" button and it would look at the website and tell me the text boxes and gives me there form and item number. Would be helpful.

Any suggestions?

UPDATE:  I've went back and modified the browser to use the testpage that came with OP program to see if it can populate any box after the first using the :  Browser.Document.Forms(0).GetElementsByTagName("Input").Item(0).SetAttribute("Value", "test1")
 method and ran into the same problem.  Even though I added more lines with higher Item number, it just populated the first box (txtbox in this case).  Hope someone can help.

----------


## kleinma

It is a security limitation of the IE DOM.

Imagine you went to some webpage, and the webpage had a file upload input element on it, that was prefilled with some sensitive file from your computer, and when the page loads, javascript has the page automatically submit, and some personal file from your computer is uploaded to someones server....

For that reason, the Document Object Model does not expose the value property of <input type=file> elements. That means you can not set those via code.

----------


## roiegat

> It is a security limitation of the IE DOM.
> 
> Imagine you went to some webpage, and the webpage had a file upload input element on it, that was prefilled with some sensitive file from your computer, and when the page loads, javascript has the page automatically submit, and some personal file from your computer is uploaded to someones server....
> 
> For that reason, the Document Object Model does not expose the value property of <input type=file> elements. That means you can not set those via code.


Guess I set them wrong...just figured out a way.  I wrote this handy little sub:

    Private Sub update_text(ByVal field As String, ByVal input_text As String)
        Browser.Document.All(field).Focus()
        SendKeys.Send(input_text)

    End Sub

So I just send that I want to update "file1" and the text.  It sets the focus on the box and then used sendkeys to type in the file name.  

Thanks for the info!

----------


## kleinma

yeah, using sendkeys could work because sendkeys mimics user input. Since javascript doesn't have access to sendkeys, there is no direct browser security risk there.

Just make sure you do extensive testing with sendkeys, as it sends keystrokes to the active window, so you shoudl always make sure the desired window has focus before calling sendkeys

----------


## roiegat

> yeah, using sendkeys could work because sendkeys mimics user input. Since javascript doesn't have access to sendkeys, there is no direct browser security risk there.
> 
> Just make sure you do extensive testing with sendkeys, as it sends keystrokes to the active window, so you shoudl always make sure the desired window has focus before calling sendkeys


That correct.  I learned this the hard way when I was trying to debug the code and the program would hang on me.  So I have to put a breakpoint after the sendkey command.

----------


## knds

Hi,
   I am a newbie on VB, using VS2005.
   How do I use InvokeMember if the button does not have a name?

html - <input id="uploadButton" type="submit" value="Upload Video">

code - wb.Document.Forms("uploadVideoFileForm").InvokeMember("submit") - nothing happens
           wb.Document.Forms("uploadVideoFileForm").InvokeMember(????)


what do i do? or is there a basic way to go around with this.
Thanks in Advance!

----------


## kleinma

instead of using the form specifically, try Invoking a click on the submit button using its ID of "uploadButton"

----------


## knds

> instead of using the form specifically, try Invoking a click on the submit button using its ID of "uploadButton"


It worked!
but you know what somewhere in my tests im sure i did that, ive been working with it for 4 hours and its almost 2am, now, how do I get rid of ghosts inside this program, hmmm... lesser errors to go! weeeeeeee

anyways BIG BIG thanks again, 
knds  :Wink:

----------


## kleinma

no problem  :Wink:

----------


## psmith811

I'm attempting to
1) click a single checkbox on the loaded page (which should redirect the page in the process)
2) click a URL on the next page

Apparrently the checkbox is beyond my scope because I can't seem to get it to work.  There are 5 forms on the page, and the check box is in the 4th (index 3?).  Also in that form is a hidden value which is specified before the checkbox name.  Here is some code I'm working with:



```
Public Class frmMain

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim tmpStr As String = "http://localhost/CASE_NUMBER=" & CStr(TextBox1.Text)
        wb.Url = New System.Uri(tmpStr)
    End Sub

    Private Function GetCurrentWebDoc() As MSHTML.HTMLDocument
        Try
            Return DirectCast(wb.Document, mshtml.HTMLDocument)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Function GetCurrentWebForm() As MSHTML.HTMLFormElement
        Try
            If GetCurrentWebDoc.forms.length > 0 Then
                Return DirectCast(GetCurrentWebDoc.forms.item(3), MSHTML.HTMLFormElement)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Sub ClickCheckBox()
        Dim MyInputElement As MSHTML.HTMLInputElement = DirectCast(GetCurrentWebForm.item("checkBoxName", 3), MSHTML.HTMLInputElement)
        MyInputElement.checked = True
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        ClickCheckBox()
    End Sub

End Class
```

Unfortunately I can't really post the HTML I'm working with, but I could cut and past relevant portions if I knew what would help.

Thanks for any suggestions!

----------


## kleinma

Is the checkbox actually called "checkBoxName" in the HTML code?

----------


## psmith811

no, but I changed it to protect the innocent...  I'll PM you the form code itself.

----------


## kleinma

it works fine. I PMed you with the code that works.

----------


## knds

Hi, me again,

Can InvokeMember be used to click a dynamic button? If not is there a way around this for my auto login to work?

html code:
<a onclick="signInSubmit( document.signInForm.login.value, document.signInForm.password.value, document.signInForm.rememberLogin.checked, 'signInForm_err', document.signInForm.source.value )" class="dynaBtn" title="Sign In"><span>Sign In</span></a>&nbsp;

Im Using VB on VS2005

Thanks,
knds

----------


## kleinma

if you look at my example project you will see an example of calling javascript that is in the HTML page from VB code. You could use that example to call the signInSubmit javascript function from VB code, passing the given values that it expects. That should do it.

----------


## knds

> if you look at my example project you will see an example of calling javascript that is in the HTML page from VB code. You could use that example to call the signInSubmit javascript function from VB code, passing the given values that it expects. That should do it.


I followed the script on your sample application, would there be reasons why my javascript function wont execute? Nothing is happening, I am now trying to click a link with a js function to turn off a flash part on the site so that I could write on the text box

vb code:
GetCurrentWebDoc.parentWindow.execScript("switch_non_flash_uploader()", "javascript")

html code:
<p> <a> onclick="switch_non_flash_uploader()" href="#"> Click Here </a> if you are having problem with the uploader


Thanks
knds

----------


## kleinma

I am not sure why it would not execute. It would be hard for me to guess without being able to see the actual page you are trying to manipulate. Is it a public URL so I can look at it?

----------


## knds

> I followed the script on your sample application, would there be reasons why my javascript function wont execute? Nothing is happening, I am now trying to click a link with a js function to turn off a flash part on the site so that I could write on the text box
> 
> vb code:
> GetCurrentWebDoc.parentWindow.execScript("switch_non_flash_uploader()", "javascript")
> 
> html code:
> <p> <a> onclick="switch_non_flash_uploader()" href="#"> Click Here </a> if you are having problem with the uploader
> 
> 
> ...


Im not sure why my code doesn't fire the jv function but a friend of mine did this:
wb.Navigate("javascript**:switch_non_flash_uploader();")

it worked... im a newbie on this and I didn't inquired further. well i just wanted to share so others may consider this...

thanks to kleinma, for your time... on answering my questions...  :wave:

----------


## knds

I searched on this thread re: frames, does anyone had a success filling up values on a frame?

knds

----------


## shakti5385

Sir guide me
My Problem I want to open vbforums.com  but login using the windows application.

I just open the your link but how to set the value of user name and the password in that website!!

I am not getting please guide me

Thanks!!

----------


## kleinma

if you are using my sample code, then you could use the GetCurrentWebDoc to get the current webpage document, and then grab whatever form you want by name or by its index in the collection



```
Dim MyForm As mshtml.HTMLFormElement = DirectCast(GetCurrentWebDoc.forms.item("form name here"), mshtml.HTMLFormElement)
```

----------


## kleinma

yes in the getcurrentwebform method in my example code, you will see it is specifically grabbing form at index 0. Just change that 0 to whatever number index you want to grab. You could also change the function to allow you to pass in an integer as a parameter, and use that to indicate which form you actually want to retrieve from the webpage document.

----------


## kleinma

No problem.

Check back soon, I will be releasing source for an extended WB control that uses the .NET 2.0 built in webbrowser control instead of the COM based one, but has all the features that the 2 provide.

----------


## kleinma

when you run into this type of situation, try to figure out what action you are trying to simulate versus the result you want (sometimes the opposite is true). In this case, you want to simulate clicking on an image. It just so happens that the result is submitting the form.

Try this code to simulate clicking the image, which in turn should fire any code attached to that image.



```
DirectCast(GetCurrentWebDoc.images.item("ctl00$Main$postComment$postcommentImageButton"), mshtml.HTMLImg).click()
```

if that name value doesn't work, try the ID instead ("ctl00_Main_postComment_postcommentImageButton")


I do hope you are making some sort of "utility", and not anything that could be used maliciously to spam comments all over myspace.  :Wink:

----------


## kleinma

Sorry, I misread it as just an image (as in <img> tag) and not an input element of type image.

For some reason, I can't seem to access the specific element when its type image via the forms item collection. However this code seems to work:



```
        Dim MyImageElement As mshtml.HTMLInputElement = DirectCast(GetCurrentWebDoc.all.item("ctl00_Main_postComment_postcommentImageButton"), mshtml.HTMLInputElement)
        MyImageElement.click()
```

----------


## rbxslvr

It told me "Unable to cast object of type 'System.Windows.Forms.HtmlDocument' to type 'mshtml.HTMLDocument'." for the following line of code



```
Return DirectCast(WebBrowser1.Document, mshtml.HTMLDocument)
```

in the GetCurrentWebDoc function.


It is causing null errors when I try to set a value.  (I took out the exception stuff to figure out where the null value was comming from).

I think it is because I am trying to use it with a .dll page... but it is written in HTML.  Is there a way I can use this same method for a .dll page?  

I'm creating a program that you can enter info into and it will use that info to fill out the eBay Sell an item page, because I like to enter everything in when I'm in the car on my laptop, then when I have an internet connection, I can just plug it in and use it to list the items.

----------


## rbxslvr

> A .dll page? ***.....
> 
> Are you using the Web Browser control or the .net 1.1 ActiveX Control? Thanks.


web browser control in .net

eBay uses .dll pages... "http://my.ebay.com/ws/eBayISAPI.dll?MyEbay"


(That url only works if you are logged in)

----------


## kleinma

Yes, until I actually finish up my 1.1+2.0 browser control that will have all the functionality of both  :Wink:

----------


## dwarfs

Hi, I am also trying to code using VB6 to pass values from my application and fill the values in the web pages and submit the page. But the web pages are in frames. I am new to all these... :Confused:

----------


## dwarfs

hi kleinma, my office blocked downloading of zip file. Can you email me the sample codes? My email is dwarfs38@gmail.com. Thanks.

----------


## work4love

I have a vb program using webbrowser control. I wonder is there a way for me from vb to click an anchor tag thru code.

----------


## kleinma

VB6 or VB.NET?

----------


## bigdave

> Sorry, I misread it as just an image (as in <img> tag) and not an input element of type image.
> 
> For some reason, I can't seem to access the specific element when its type image via the forms item collection. However this code seems to work:


kleinma, first Id like to say a big thanks for this thread, it has been invaluable to me.

However, I had a page input button I wanted to click with no ID or Name along with several other input buttons on the page that I didnt want to click. To get round this I identified the button by its .src

heres the code..



```
            Dim thisObj As Object
            Dim butInput As mshtml.HTMLInputElement
            thisObj = AxWebBrowser1.Document.getElementsByTagName("input")
            For Each butInput In thisObj
                If butInput.src = "TheNameOfTheImage.gif" Then
                    butInput.click()
                End If
            Next
```

If you or anyone has a better way of doing it Id be interested to know, but this worked for me and maybe it'll help someone else too.

----------


## kleinma

Off the top of my head I can't think of any other way of doing it. It does become a bit trickier when you have to deal with HTML that doesn't provide all the tags that it should (like a name or ID tag).

So what you are doing is fine.

----------


## extreme.aly

cant we simply click on a form's submit button with the original webbrowser???

----------


## kleinma

yes of course you can, but this thread is about automating input and interaction on webpages via VB code.

----------


## extreme.aly

noo.. i mean automatically click on a submit button... because i'm having a problem while using the navigate2 function of axshdocvw...and i'm getting the same error when i use the InvokeMember("click") function of the original webbrowser provided in VB2005 expresss ed.  here is the error screenshot:

----------


## kleinma

the VB2005 managed webbrowser control and the COM webbrowser control act a bit different.

If you downloaded my sample application, there is a "submit form" example included.

----------


## extreme.aly

yeah i tried to to make it for my application but it show me the error when i use Navigate2 function...

----------


## kleinma

Well I am not sure why you are using the navigate2 method...

usually when you are on a page, and you want to submit it, you just simulate the submit button being clicked. This is what my example code does.

It sounds like you are trying to do something different.

----------


## extreme.aly

noo...i've no page loaded yet..i'm loading it when the app starts...

look..i got a webform, which requires some dates and to be submitted...and i want the resulted html code...now i want it to be done multiple time with different dates..like
for i as integer = 0 to 100
' fill the date in the webform
' submit the form
' get the resulted html
' parse the html code
next

----------


## kleinma

you can't quite do it in a loop like that, because the webbrowser is event driven. It fires events when it is doing things so you know what state it is in, and you know when you should proceed.

So to accomplish a repetitive task like that, you would need to do something like the following:

Lets say you have page1.htm (which is the page that has the fields that need to be filled in), and page2.htm (which is the page the form submits to and has the resulting HTML code you want)



```
-Navigate to page1.htm
-When the DocumentCompleted event of the webbrowser fires the page has fully loaded
    check the current URL of the WB control
        if its page1.htm, fill in the values you want and submit form
        if its page2.htm, then page1 was just submitted, so get the resulting HTML code.
```

----------


## extreme.aly

yeah i have done the same thing in the original browser but i have to click to button each time... the code is something like this:


```
dim counter as integer = 0
prv sub form_onload(...)
webbrowser1.documenttext = mycode
' press submit button code should be here
end sub

prv sub webbrowser1_documentcomplete(...)
if webbrowser1.documenttitle = submitted_page_title then
  parse(webbrowser1.documenttext)
  if counter <> 101 then
    webbrowser1.documenttext = mycode
    ' press submit button code should be here
  end if
end if
end sub

prv sub parse(html as string)
' parse html
counter += 1
end sub
```

i just want the button to be clicked automatically without making a BIG change..i think you understand

----------


## karthik120

Hi kleinma, 
I have been following this post for couple of days. I would like to mention that I have never seen anyone so HELPFUL.. You rock!! :Thumb:  

well, i got a problem in doing the same thing. I am using Vb.net 2005 express edition, wherein i am creating an application, that would send in data to the web form fields and get the results. It's actually a ASP.NET webpage, that calculates  based on the values entered in the fields. 

I don't know why Mmhtml code, didn't work for me, so i am working with the web browser control 2.0, with the following code:

WebBrowser1.Document.All.Item("IDTextBox").InnerText() = "202"
WebBrowser1.Document.All.Item("PasswordTextBox").InnerText() = "123"
WebBrowser1.Document.All.Item("SelectButton").InvokeMember("click")

PROBLEM: after I execute this code, the web browser loops it, making the page to reload, input the variables and again click it.. it forms a vicious circle.. :Confused:  

any suggestions..

----------


## kleinma

What event did you put that code in?

----------


## karthik120

ohh great!! 
 :Big Grin:  salutations to you...

you are online..

well i posted this code as follows:


Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        WebBrowser1.Document.All.Item("IDTextBox").InnerText() = "202"
        WebBrowser1.Document.All.Item("PasswordTextBox").InnerText() = "123"
        WebBrowser1.Document.All.Item("SelectButton").InvokeMember("click")
End Sub

I am really new to this field, any help would work a long way for me..

----------


## kleinma

Are you able to provide me the URL that you are trying to work with? That makes it easier for me to be able to give you a 100% working answer.

The problem most likely lies somewhere in the fact that an ASP.NET page posts back to itself, not a different page, which could cause the loop you describe.

----------


## karthik120

well.. its only for you.. 

[REMOVED]

if you have it saved, i can remove it from the public access.. This forms a part of high profile research group..i hope you understand my situation.. :Smilie:

----------


## kleinma

yeah I saved it.

You need a mechanism, either in your VB app, or in the ASP.NET page, to let you know the current state of the ASP.NET page.

For example, the only visual indicator I see on that page to let me know if an ID/Password were submitted, is the label that says "Select a building" which then changes to "You selected: oh god in Atlanta, Georgia" when I put in the ID/Password.

If you have access to the ASP.NET source code, I would either add a hidden field to indicate if an ID/Password has been submitted. The VB app could then read the value of that hidden field to decide if it should refill the boxes and submit, or not. 

If you don't have access to the source code, you could try parsing out the HTML text to find the words "Select a building:" to indicate if you should autofill and submit, however that is more error prone and subject to break if the text on the page ever changes.

----------


## karthik120

i tried stopping the navigation after i was able to invoke the submit button. But, i was not able to invoke "Click" button the next time in the same page..  :Ehh:

----------


## karthik120

OOps... that would hit hard on me.. 

If you have seen, there are multiple button on the webpage, i don't know if i could save the page temporarily, and hit the next button to execute the complex calculation.... :Mad:  

Any other way out of this mess.. 

It actually selects the building on the first button, then we are allowed to change parameters, then the next button would be for saving the changed parameters for that selected building.. Few more buttons that would lead you to next page, where we got to do the same for other calculation.. .. :Cry:

----------


## kleinma

well do you have access to the ASP.NET source code?

----------


## karthik120

Yeah, but  i ain't know much about ASP.NET, but i know it is in complete mess.
So i was trying to work other way out.. 

I have the aspx file attached.. If you could have a look at it..

----------


## karthik120

Any solutions...  :Confused:

----------


## kleinma

I don't need the aspx file really.

My suggestion would be that you add a hidden field to the aspx page. Call that field hdnStatus

In the code behind for the aspx page, in the button click code for each button have that button set the hdnStatus field. Then your VB app that hosts the WB control can query that field to get the current status:

For example

When user puts in ID/Password and clicks the button to get the building, the ASPX page fires the codebehind code for the button click event of that button. In that code you verify ID/Password and if its correct you display the building they selected. You should also there set the hdnStatus field with some value to indicate there has been a successful login. Lets say you set the hidden field text to "BUILDING_RETRIEVED"

Then in your VB code, in the documentcompleted event of the WB control, look at the value of hdnStatus in the webpage. If its blank, then that should indicate nothing has been done, and the ID/Password should be automatically entered and the button should be clicked. If it says "BUILDING_RETRIEVED" then it should not autofill and click the button again.

You could use this same approach for all the buttons on the page. Just set different values in the hidden field, and that value can be looked at by your VB app so it can take the proper action.

Hope this makes sense.

----------


## karthik120

well makes a lot sense.. :Blush:  i would try to work on it.. 

One more dumb question  :Roll Eyes (Sarcastic):  
Is there a way to trigger "code behind code" that leads me to the solution without clicking the button? If yes, it would make my life a lot easier..

----------


## kleinma

not really, in order for the ASP.NET page to behave properly, you need to fire the button click in the HTML. This is because ASP.NET pages employ built in javascript to do certain things when a button is clicked and the page posts back to the web server. If you were to simply submit the form without clicking the button, you would get unknown/undesired results.

Just try the method I described to you before, I think once you get it going, you will find it very easy to implement.

----------


## karthik120

ohh.. i didnt notice that there was a new page...

Though i have access to aspx files.. i don't think my professor would allow me to add anything to it. What i am developing is an add in (windows application) feature. They would like the asp page to function as it was. How about solution 2: parsing out HTML for the button? I'm sure, the webpage contents will never be changed..

----------


## karthik120

how should i parse the webpage to get to the button..

----------


## kleinma

you dont need to get the button, since the only thing that visibly changes on the page is the text telling you to either enter an ID/Password, or it tells you what building you selected, you should look at the HTML source in the browser control, and look for the specific strings that will indicate to you if the fields were already filled out and the button was clicked.

----------


## karthik120

Alrighto...
You are amazing..
Thank you so much.. would work on it..

----------


## karthik120

:Eek Boom:   it didn't work either, do you think HTTPwebreqest might be helpful, for my problem..

----------


## rbxslvr

I need to click a submit button,  based off of this information...

Type - "Submit"
TabIndex - "1"
AccessKey - "s"
Value - "Save Signature"
Class - "button"


there is no name or id... so how do I go about doing that (without focusing the control that comes before it when you tab through, and then using sendkeys.send("{TAB}{ENTER}")



Here is the actual code for the button


```
<input type="submit" class="button" value="Save Signature" accesskey="s" tabindex="1" />
```

----------


## kleinma

if the button has no ID or Name value, then you can do one of 2 things

1) Submit the form directly by calling the forms .Submit() method (which is shown in my sample code)

2) Loop the elements of the form until you find one thats value is equal to "Save Signature" and then you know you are on the right input element, and you can invoke a click on it.

I think #1 is the better method.

----------


## rbxslvr

> if the button has no ID or Name value, then you can do one of 2 things
> 
> 1) Submit the form directly by calling the forms .Submit() method (which is shown in my sample code)
> 
> 2) Loop the elements of the form until you find one thats value is equal to "Save Signature" and then you know you are on the right input element, and you can invoke a click on it.
> 
> I think #1 is the better method.


How about this, instead of doing that...


```
<form action="profile.php?do=updatesignature" enctype="multipart/form-data" method="post" name="vbform" onsubmit="return vB_Editor['vB_Editor_001'].prepare_submit(0, 0)">
```

What if I use the line WebBrowser1.Document.all.item("vbform").invokemember("post")

I can't try it because I don't have VB on this computer.  So, I'm wondering if that would work with a normal web browser for the form?  I'd rather use a regular web browser if I can, plus it would be just 1 line of code, rather than several functions.

----------


## kleinma

I dont think that will work, but i suppose you could try it.

I still think you should just call the forms .Submit method.

----------


## ianp

Hi This is one of the best examples I've seen. I'm just starting with some aspect of dotnet applications. I've scanned the thread but I cant see an answer to (what is probably very obvious once you know how) where the reference for the browser (used) comes from. Creating a new project from scratch where is the library for the browser version used here? The only refence in the distributed (zipped) project is to some dlls in bin/debug. What do I reference on an otherwise blank machine. What to I include in the setup for an exe based on this solution? Could you please expain this aspect of the solution please?

appologies oif this is answered somewhere, but I did not see it.

Many thanks

Ian

----------


## kleinma

sure.

to get this setup you need to do the following

1) create a new Windows Application in Visual Studio
2) select "add reference" from the project menu, and under the .NET tab try to locate microsoft.mshtml (which is microsoft.mshtml.dll)

If you don't see it there then try to search your compute rfor microsoft.mshtml.dll. if you don't have it at all, then you can download it from post #88 in this thread (it is also included in the download of the sample project in post #1)

mshtml.dll is the HTML parsing engine. It is what allows you to parse and manipulate individual HTML elements in the browser control.

So once you have that done its on to step 3

3) right click in your toolbox (where all the controls are) and select "Choose Items" Then select the "COM components" tab when the dialog comes up.

Scroll down and find "Microsoft Web Browser" and click the checkbox and then click OK. This will add the COM based webbrowser control to your toolbox so you can drag it to a form.

That is all there is to it. From there you can use my example code to see how you actually do the manipulations of the webpage.

----------


## ianp

thank you very much

I had cracked 1&2 and was stubling over 3.

Very helpful, much appreciated.

----------


## MondeoST24

Hi,

Thanks for the the example code, its excellent.

I hope you can help me with this.

Im using your example to set the value of a drop down list, then i'm calling the postback javascript to populate a second drop down on the page which is based on the value of the first.

So I have



```
DirectCast(GetCurrentWebForm.item("MakeAndModelSearch1:m_make"), MSHTML.HTMLSelectElement).value = "Subaru".ToUpper
        GetCurrentWebDoc.parentWindow.execScript("__doPostBack('MakeAndModelSearch1$m_make','')", "javascript")
```

Then I want to set the value of the second dropdown - BUT, my code is trying to set it before the postback has occurred and it has been populated with values.



```
            DirectCast(GetCurrentWebForm.item("MakeAndModelSearch1:m_model"), MSHTML.HTMLSelectElement).value = "Impreza".ToUpper
        GetCurrentWebDoc.parentWindow.execScript("__doPostBack('MakeAndModelSearch1$m_model','')", "javascript")
```

I've tried to use a Thread.Sleep(2000) between the two bits of code, but although the thread sleeps it stops the first postback happening.

How can I get around this? I need to hold off executing the second statement until the post postback has completed.

Thanks

----------


## kleinma

you need to use the DocumentComplete event of the webbrowser control. This event fires when a page has fully loaded. So when you do the first postback, the DocumentComplete event will fire when the page has posted back and reloaded in the browser.

----------


## MondeoST24

Great! Thanks.

Another question, i'm working with this page

https://www.bosbusinesscars.co.uk/Default.aspx

How to I get the image on the left marked CAR SEARCH to click.

I have this,

DirectCast(GetCurrentWebForm.item("MakeAndModelSearch1:m_search"), MSHTML.HTMLImg).click()

But I get a NullReferenceException, did I get the element name wrong?

Thanks

----------


## kleinma

here



```
DirectCast(GetCurrentWebDoc.getElementById("MakeAndModelSearch1_m_search"), mshtml.HTMLInputElementClass).click()
```

----------


## ianp

Hi

I have two problems which I'm trying to resolve and which I hope you can help:

1. I'd like to pick up the ellement attibutes that the mouse is currently hovering over: name, id etc

2. I have a test login page, which (I presume supports cookies) once I have logged in, the browser retains the information and automatically logs in when I visit the page. I would like to prevent this behaviour. (this is mainly for testing)

You are very helpful but is there any source of information on this control from MS?

----------


## tnooc

I have read through the entire string and I saw a couple people ask how to use this with a web page that has frames.  Has that been posted here or in another string yet.

----------


## 4xzer0

Hi
i'm trying to fill in a textbox on a page for a login

I've tried this code:

WebBrowser1.Document.GetElementsByTagName("input").Item(22).SetAttribute("value", txtUser.text)

but it says "Specified cast is not valid" on this line.

how can I fix this?


thanks to anyone who helps  :Smilie: 

edit: btw, this is for the ebay login page, here 

https://signin.ebay.co.uk/ws/eBayISA...k/&_trksid=m37

----------


## MondeoST24

In my web browser when the page goes from secure https to http I get a dialog box which says "this page contains secure and non secure items etc etc"

Is there anyway to disable this prompt somehow?

Thanks

----------


## kleinma

> In my web browser when the page goes from secure https to http I get a dialog box which says "this page contains secure and non secure items etc etc"
> 
> Is there anyway to disable this prompt somehow?
> 
> Thanks


No. that prompt means that some items (usually pictures) are being pulled from an HTTP source and not an HTTPS source. This is actually a problem with the website not being done correctly versus a problem with the webbrowser.

----------


## 4xzer0

Kleinma can you help me please with the ebay login?  :Smilie: 
I am using visual studio 2005..

----------


## kleinma

> Kleinma can you help me please with the ebay login? 
> I am using visual studio 2005..


are you using the 2.0 webbrowser control from the toolbox? Or are you using the COM based control?

----------


## 4xzer0

> are you using the 2.0 webbrowser control from the toolbox? Or are you using the COM based control?


yes i'm using the webbrowser 2.0 control from the toolbox..

did you see what i tried earlier? (about 4 posts up from here)

----------


## kleinma

> yes i'm using the webbrowser 2.0 control from the toolbox..
> 
> did you see what i tried earlier? (about 4 posts up from here)



seems to work fine for me using this code



```
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        WebBrowser1.Document.Forms("SignInForm").All("userid").SetAttribute("Value", "hello")
        WebBrowser1.Document.Forms("SignInForm").All("pass").SetAttribute("Value", "world")
        WebBrowser1.Document.Forms("SignInForm").InvokeMember("submit")
    End Sub
```

----------


## tnooc

kleinma, your code has been very helpful to me - I've learned alot.  The one problem I had was that the website I was testing with used frames, and I kept getting a null reference error.  I finally managed to get it work with the frames by doing the following:

Dim objDoc1 as mshtml.HTMLDocument
Dim objWin1, objWin2 as mshtml.IHTMLWindow2
Dim objFrame1 as mshtml.FramesCollection

objDoc1 = AxWebBrowser1.Document
objWin1 = objDoc1.parentWindow
objFrame1 = objWin1.frames
objWin2 = objFrame1.item(2) 'Was working with 3rd Frame
objWin2.document.all.item("USERID").value = "Text"

Thanks for all the effort you have put into this string - you have helped alot of us.

----------


## 4xzer0

> seems to work fine for me using this code
> 
> 
> 
> ```
>     Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
>         WebBrowser1.Document.Forms("SignInForm").All("userid").SetAttribute("Value", "hello")
>         WebBrowser1.Document.Forms("SignInForm").All("pass").SetAttribute("Value", "world")
>         WebBrowser1.Document.Forms("SignInForm").InvokeMember("submit")
> ...


Oh, thanks a lot kleinma !
this code works great  :Smilie:

----------


## MondeoST24

Kleinma,

Do you know how to instantiate/initialize the ax web browser control manually?

I want to create it from scratch in a seperate thread to the UI, I can create it and it appears on the form however when I call its navigate method I get this

Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was unhandled

Thanks

----------


## kleinma

> kleinma, your code has been very helpful to me - I've learned alot.  The one problem I had was that the website I was testing with used frames, and I kept getting a null reference error.  I finally managed to get it work with the frames by doing the following:
> 
> Dim objDoc1 as mshtml.HTMLDocument
> Dim objWin1, objWin2 as mshtml.IHTMLWindow2
> Dim objFrame1 as mshtml.FramesCollection
> 
> objDoc1 = AxWebBrowser1.Document
> objWin1 = objDoc1.parentWindow
> objFrame1 = objWin1.frames
> ...


I know there are issues with frames and manipulating the DOM properly. I haven't really had time to dig in and try to get it working. Do you have a specific URL to reference?

----------


## kleinma

> Kleinma,
> 
> Do you know how to instantiate/initialize the ax web browser control manually?
> 
> I want to create it from scratch in a seperate thread to the UI, I can create it and it appears on the form however when I call its navigate method I get this
> 
> Exception of type 'System.Windows.Forms.AxHost+InvalidActiveXStateException' was unhandled
> 
> Thanks


I will start off by asking why you would need to put it in a seperate thread? The control itself is actually multithreaded in that navigations and such are not held up by the windows app consuming the browser control unless your code tells it to via one of the exposed events/properties of the browser control.

----------


## Mark Douglas

Hi Kleinma, Great piece of code here. Has saved me soo much time filling in forms on webpages. Now I have a problem and was hoping maybe you can help. I posted on the VB.net forum but no answers and saw you have been posting back on this thread. So hopefully you can help me out.

Here is my post.

Again thanks for posting this code.

http://vbforums.com/showthread.php?p...62#post2995362

----------


## kleinma

> Hi Kleinma, Great piece of code here. Has saved me soo much time filling in forms on webpages. Now I have a problem and was hoping maybe you can help. I posted on the VB.net forum but no answers and saw you have been posting back on this thread. So hopefully you can help me out.
> 
> Here is my post.
> 
> Again thanks for posting this code.
> 
> http://vbforums.com/showthread.php?p...62#post2995362


The problem has nothing to do with the table. The problem is the page you were trying to manipulate has more than one form. If you look through my sample code, the GetCurrentWebForm function has comments above it. I mention that the sample code assumes the page only has one form, as it grabs the first form on the page (index 0). Since the form you want to manipulate is actually the second form in the page, you need to grab that one instead.

You can add this function to the existing GetCurrentWebForm() function (they will overload eachother)



```
    Private Function GetCurrentWebForm(ByVal FormName As String) As mshtml.HTMLFormElement
        Try
            If GetCurrentWebDoc.forms.length > 0 Then
                Return DirectCast(GetCurrentWebDoc.forms.item(FormName), mshtml.HTMLFormElement)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
```

It does the same thing as the one that takes no parameters, but this one takes one, allowing you to specify the name of the form you want. Your forms name was "mainform", so you can use code like this:



```
        With GetCurrentWebForm("mainform")
            DirectCast(.item("address"), mshtml.HTMLInputElement).value = "Value Here"
        End With
```

Which works fine.

----------


## MondeoST24

> I will start off by asking why you would need to put it in a seperate thread? The control itself is actually multithreaded in that navigations and such are not held up by the windows app consuming the browser control unless your code tells it to via one of the exposed events/properties of the browser control.


Hi Kleinma,

The app I am building is for price comparison, it basically needs to connect to 7 sites, fill them in and then get information from the results page and present /format all the results to the user. The scraping of each site takes about 30 seconds, so I wanted to run them all concurrently using backgroundworkers if possible.

What do you think, have I got the approach wrong?

Thanks again.

----------


## DC123

> sure.
> 
> to get this setup you need to do the following
> 
> 1) create a new Windows Application in Visual Studio
> 2) select "add reference" from the project menu, and under the .NET tab try to locate microsoft.mshtml (which is microsoft.mshtml.dll)
> 
> If you don't see it there then try to search your compute rfor microsoft.mshtml.dll. if you don't have it at all, then you can download it from post #88 in this thread (it is also included in the download of the sample project in post #1)
> 
> ...


Hi,

Thanks for this info but when I get to step 2 microsoft.mshtml.dll does not appear under the .NEt tab but it is in my windows/system32 directory. How do I get it to appear under the .NET tab. I am using VB2005 Express, thanks.

----------


## kleinma

lol, well read over what you quoted me saying one more time..

I stated the following:



> If you don't see it there then try to search your compute rfor microsoft.mshtml.dll. if you don't have it at all, then *you can download it from post #88 in this thread* (it is *also included in the download of the sample project in post #1*)

----------


## ianp

Hi Kleinma

I have a problem with a login form: if I enter the text (username and password) manually - fine. If I cut and paste the same information into a standard browser- the site returns a "failed login". If I try to automate with the Browser control then its the same as cut and paste.

Have you any thoughts please?

I can post you the web page HTML off line if that helps.

----------


## kleinma

I can't really help with that information. You would need to provide more and I will see if I can help or not.

----------


## DC123

> lol, well read over what you quoted me saying one more time..
> 
> I stated the following:


I already have the microsoft.mshtml.dll in my windows/system32 directory but it does not appear under the .NET tab. Is there a missing step that makes it appear. Thanks.

----------


## kleinma

there is also a "browse" tab. Use that instead of the .NET tab when setting the reference and browse the the system32 folder.

----------


## OnlineNoob

> when you run into this type of situation, try to figure out what action you are trying to simulate versus the result you want (sometimes the opposite is true). In this case, you want to simulate clicking on an image. It just so happens that the result is submitting the form.
> 
> Try this code to simulate clicking the image, which in turn should fire any code attached to that image.
> 
> 
> 
> ```
> DirectCast(GetCurrentWebDoc.images.item("ctl00$Main$postComment$postcommentImageButton"), mshtml.HTMLImg).click()
> ```
> ...




What a great resource this thread has been, one of very few on the internet for this subject matter.  Specific to this issue, my company now has it's own myspace page and it's my job to work it.  %-(

I'm first seeing if it's feasible to do by generating this temporary test solution. I need to auto-comment anyone who sends us a comment or becomes our friend.  Akin to this post, you showed how to click on an image, but I'm trying to fill in a textarea form field with your example.  However, I'm running into problems.  Here is the text area field data source I'm trying to automate similar to the poster above:



```
<textarea name="ctl00$cpMain$postComment$commentTextBox" rows="5" cols="40" id="ctl00_cpMain_postComment_commentTextBox" style="width:100%;"></textarea>
```

I used your source project to try and autofill the textarea box but it's not working.  My test program throws an exception stating "Object reference not set to an instance of an object") It keeps telling me that I need to declare a new object.  I've tried both ID & Name of control and here is a sample code I'm trying:



```
Public Class BuiltInBrowser

    Private Sub BuiltInBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        wB.Navigate("http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=8")

    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetText.Click
        SetTextareaText(txtMessage.Text)
    End Sub

    Private Sub SetTextareaText(ByVal Text As String)
        Try
            DirectCast(GetCurrentWebForm.item("ctl00cpMain$postComment$commentTextBox"), mshtml.HTMLTextAreaElement).value = Text
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
        Try
            Return DirectCast(wb.Document, mshtml.HTMLDocument)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
        Try
            If GetCurrentWebDoc.forms.length > 0 Then
                Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

   
End Class
```


Any help in this matter would be GREATLY appreciated!

----------


## kleinma

OnlineNoob,

The problem MAY be that the page you are trying to manipulate has more than one form on it.

If you look at my code for GetCurrentWebForm, it checks to see if there is at least one form, and then returns that first form. However the textarea you are looking to manipulate may very well be in a second, third, or Nth form on the webpage. So you may have to modify the code to return a reference to a different form in order to manipulate the textarea on it. I believe this is mentioned in the comments in my code for that routine.

My example only grabs the first form because the example HTML page I included with the sample project only has one form, and is after all, just an example.

Check that out first, then post back with how you make out.

----------


## OnlineNoob

hi Kleinma, thanks for your response.  I added a parameter to the code to make it like the following:



```
Public Class BuiltInBrowser

    Private Sub BuiltInBrowser_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        wB.Navigate("http://comment.myspace.com/index.cfm?fuseaction=user.viewProfile_commentForm&friendID=8")

    End Sub

    Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSetText.Click
        SetTextareaText(txtMessage.Text)
    End Sub

    Private Sub SetTextareaText(ByVal Text As String)
        Try
            DirectCast(GetCurrentWebForm(2).item("ctl00_cpMain_postComment_commentTextBox"), mshtml.HTMLTextAreaElement).value = Text
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

    End Sub

    Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
        Try
            Return DirectCast(wb.Document, mshtml.HTMLDocument)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Function GetCurrentWebForm(ByVal intFormNumber As Integer) As mshtml.HTMLFormElement
        Try
            If GetCurrentWebDoc.forms.length > 0 Then
                Return DirectCast(GetCurrentWebDoc.forms.item(intFormNumber), mshtml.HTMLFormElement)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

End Class
```

Amazingly enough, i only added the parameter for the function you created and set the form n8umber to the proper number and it walaa, it worked.  However, i had to also change the textarea selected to use the ID of the contyrol because the name of the control didn't work.  Other than that, the code workds great now.  Thank you for your patience!!!!!

----------


## kleinma

glad to hear you got it working.

----------


## ianp

Hi Thanks for your previous help.

I'm not sure if I'm doing something silly. VS2005, I am trying to use SendKeys (and this was refered to earlier in this thread) and the control does not seem to programattically accept focus. If I click on it and type <Ctrl +a> then the page / frame is selected. Tabstop = true. The standard browser control seems to accept focus, but not the ax one. If I code:

browserCtl.focus
...sendkeys("{^}a")

No joy

Any thoughts please.

----------


## kleinma

ian,

check your PMs, but sendkeys is absolutely NOT the way to go to automate things in a browser. There are way too many hiccups and chances for error.

----------


## demausdauth

This was a fantastic help and very interesting to look through. Really enjoyed. Thanks kleinma.

Incidentally, this is what i ended up coding to access frames.



```
 Private Function GetWebFrameObject(ByVal PassDocumentObject As Object) As mshtml.HTMLWindow2
        Try
            Return DirectCast(PassDocumentObject, mshtml.HTMLWindow2)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    Private Function getwebform(ByVal PassDocumentObject As mshtml.HTMLDocument) As mshtml.HTMLFormElement
        Try
            Return DirectCast(PassDocumentObject.forms.item(0), mshtml.HTMLFormElement)

        Catch ex As Exception
            Return Nothing
        End Try

    End Function

    Private Sub SetFrameTextBox(ByVal FrameNumber As Integer, ByVal ValueToSendToBox As String, ByVal FieldToFill As String)
        DirectCast(getwebform(GetWebFrameObject(GetCurrentWebDoc().frames.item(FrameNumber)).document).item(FieldToFill, 0), mshtml.HTMLInputElement).value = ValueToSendToBox
    End Sub

    Private Sub clicksubmitbuttonframes(ByVal FrameNumber As Integer, ByVal FieldToFill As String)
        DirectCast(getwebform(GetWebFrameObject(GetCurrentWebDoc().frames.item(FrameNumber)).document).item(FieldToFill, 0), mshtml.HTMLButtonElement).click()
    End Sub
```

The only thing that i didn't like about how I did this was I needed to know the exact frame index number.

----------


## SlumberMachine

Using your example code I've been able to do about 80% of a project I needed to create for work. But I have one last item to figure out. 

The page has 4 drop down menus on it, each with about 20 or more items. I need to programatically search for a specific word and choose the drop down item that matches in each one. How would I do that? Here is what I've got so far:



```
    Private Sub btnComboFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComboFill.Click

        Dim MyHTMLCombo As mshtml.HTMLSelectElement = DirectCast(GetCurrentWebForm.item("ctl00_ManagementMain_FirmwareUserControl_FirmwareFilename"), mshtml.HTMLSelectElement)

        Dim i As Integer
        For i = 0 To MyHTMLCombo.size
            If MyHTMLCombo.value.Contains(myfirmware) Then
                MsgBox("I found it")
            End If
        Next
```

----------


## SlumberMachine

> you need to use the DocumentComplete event of the webbrowser control. This event fires when a page has fully loaded. So when you do the first postback, the DocumentComplete event will fire when the page has posted back and reloaded in the browser.


I'm not sure how to use an event to handle this. For instance, say I need to navigate through 3 pages and I want it to do this all using 1 user event. How can I handle this?

1 first page load
Documentcomplete fires and I put in the second page there
second page loads
Now how do I get to the third page?

----------


## SlumberMachine

Nevermind on that second question, what I did was this (in pseudo code):

dim 1,2 as boolean = false

form load event
timer1.enabled

timer1 event
wb.navigate("webpage1")
1 = true
timer1.enabled = false

wb DocumentComplete event

if 2 = true then
wb.navigate("webpage3")
2 = false
end if

if 1 = true then
wb.navigate("webpage2")
1 = false
2 = true
end if

Thanks! although I still need help figuring out how to select those drop down items. I can use your code to figure out the index and name, but I can't select it using a word contained in an item.

----------


## kleinma

the best way to do it is to look at the webbrowsers current URL when that event fires. Then you will know what URL the user is actually viewing, so your code can take appropriate action.

----------


## SlumberMachine

> Using your example code I've been able to do about 80% of a project I needed to create for work. But I have one last item to figure out. 
> 
> The page has 4 drop down menus on it, each with about 20 or more items. I need to programatically search for a specific word and choose the drop down item that matches in each one. How would I do that? Here is what I've got so far:
> 
> 
> 
> ```
>     Private Sub btnComboFill_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnComboFill.Click
> 
> ...


Well I solved this problem, here is the solution:



```
 Dim MyHTMLCombo As mshtml.HTMLSelectElement = DirectCast(GetCurrentWebForm.item("ctl00_ManagementMain_FirmwareUserControl_FirmwareFilename"), mshtml.HTMLSelectElement)

        Dim total As Integer
        total = MyHTMLCombo.length

        Dim i As Integer
        For i = 0 To total
            MyHTMLCombo.selectedIndex = i
            If MyHTMLCombo.value.Contains("what im looking for") Then
                found = True
                Exit For
            End If
        Next
```

Yeah!

----------


## kleinma

looks good, but you should really do your loop

for i = 0 to (total - 1)

Since the total is the total number of items, and the indexes start at 0, your loop should be 0 to the total - 1.

----------


## jmbundy

This article was awesome and I learned a ton, but I have come to something a little too much for me to figure out, i am trying to navigate to a url, select all of the checkboxes, and then run a javascript code that will download them. The issue is that the table with item names, numbers, and the checkboxes seem to be done on the serverside and then just pushed to the screen so i see no id's or names for any of the check boxes. There is an image thats click event selects them all but i cannot get it clicked. Here is the source code for it:
<td class='headerbar' nowrap width='4%' align='center' id=0><img OnClick='JobTable.MarkAll()' src='images/checker.gif' width=15 style='cursor:hand'></td>

plus i would like to know how to access the table, but one thing at a time. Thanks

----------


## jmbundy

Better still, clicking that image fires a function:
function MarkAll()
I am trying this:
GetCurrentWebDoc.parentWindow.execScript("markall()", "javascript")

and getting this error:

Exception from HRESULT: 0x80020101

any idea what i could be doing wrong?

----------


## kleinma

it looks like the MarkAll function is linked up with the JobTable object since the onClick method is calling JobTable.MarkAll();

So if something like this doesn't work:



```
GetCurrentWebDoc.parentWindow.execScript("JobTable.MarkAll()", "javascript")
```

then you have to go the route of tracking down the image and clicking it. This is very easy if the image has an ID or NAME property to associate with it. Based on your HTML code above though, this image has neither, so the only thing you can do is loop the images, narrow down to the one you want, and then invoke its click method, something like this SHOULD work:



```
        Dim MyImage As mshtml.HTMLImg = Nothing
        For i As Integer = 0 To GetCurrentWebDoc.images.length - 1
            MyImage = DirectCast(GetCurrentWebDoc.images.item(, i), mshtml.HTMLImg)
            If MyImage.src.ToLower = "images/checker.gif" And MyImage.style.cursor = "hand" Then
                MyImage.click()
                Return
            End If
        Next
```

----------


## jmbundy

Thanks, the first line worked like a charm. One more question, I have this code which will let me select a file, and gives info about that file, i would like to pass a row number and return the various values at the bottom of the code. Some thing like:
for i=1 to max rows
getrow(i).jobid.value
next

Here is the code

function GetRow(id)

document.RowSelected.JobId.value = JodIdArray[id];
document.RowSelected.Status.value = StatusArray[id];
document.RowSelected.Extension.value = FileExtArray[id];
document.RowSelected.Filename.value = FileNameArray[id];
document.RowSelected.ReqName.value = ReqNameArray[id];

off to other code...

----------


## bobi1024

I read the whole thread and I can't find a solution for my problem.
What I'm doing wrong? If anyone can help me.

I want to submit username and password to this form http://iptv.bg/watch
but I can't get it work.

Here is my code (I'm using VB 6.0 and mshtml control):



```
Private Sub IPTVLogin()

    Dim objMSHTML As New MSHTMLCtl.HTMLDocument
    Dim objdoc As New MSHTMLCtl.HTMLDocument
    
    Set objdoc = objMSHTML.createDocumentFromUrl("http://iptv.bg/watch", vbNullString)
    
    While objdoc.readyState <> "complete"
        DoEvents
    Wend
    
    If InStr(1, objdoc.body.innerHTML, "Вход") <> 0 Then
        With objdoc
            .All.Item("login").Value = "username"
            .All.Item("password").Value = "password"
            .Forms(0).submit
        End With
    End If

End Sub
```

and here is the some part of the code used in that web page (they use javascript for the login, I think)



```
<div class="formtable_login">
<form method="post" action="/watch" name="loginform" onsubmit="return hash_password(this)">
<input type="hidden" name="save" value="1" />
<input type="hidden" name="go" value="index.php" />
<table border="0" cellpadding="3" cellspacing="0" class="formtable">
<tr>

	<td width="30%" align="right"><label for="login">Е-мейл адрес</label></td>
	<td width="70%"><input type="text" id="login" name="login" value="" maxlength="64" size="32" class="txt" /></td>
</tr>
<tr>
	<td align="right"><label for="password">Парола</label></td>
	<td><input type="password" id="password" name="password" value="" maxlength="64" size="32" class="txt" /></td>
</tr>
<tr>
	<td align="right"><br /></td>
	<td><label><input type="checkbox" name="rme" value="1" class="chk" /> Запомни ме на този компютър</label></td>

</tr>
<tr>
	<td align="center" colspan="2"><input type="submit" value=" Вход в IPTV.bg " class="input_submit" /></td>
</tr>
</table>
</form>
</div>
```

If anyone can help me I'll be grateful  :Smilie:

----------


## RickyH

Any idea how to get the source code of the frame object?  I can't seem to get this one.





> This was a fantastic help and very interesting to look through. Really enjoyed. Thanks kleinma.
> 
> Incidentally, this is what i ended up coding to access frames.
> 
> 
> 
> ```
>  Private Function GetWebFrameObject(ByVal PassDocumentObject As Object) As mshtml.HTMLWindow2
>         Try
> ...

----------


## demausdauth

Take a look at this to see the frames source.

----------


## kumartech

Hi kleinma,
This site is the best source for web page manipulation using GetCurrentWebDoc. I have been using your code to manipulate few sites. But some how I can't access any links, frame or any type of tag for this (http://www.insidercow.com/) site. I get the counts as "0" for all the tags.
 I am using a similar code like below.           
Dim otr As mshtml.IHTMLElementCollection = GetCurrentWebDoc.getElementsByTagName("table")

But a web page related to the above web site (http://206.222.29.162/winners.jsp), I do lot of manipulation using your example codes.
Advance thanks.

----------


## kleinma

> Hi kleinma,
> This site is the best source for web page manipulation using GetCurrentWebDoc. I have been using your code to manipulate few sites. But some how I can't access any links, frame or any type of tag for this (http://www.insidercow.com/) site. I get the counts as "0" for all the tags.
>  I am using a similar code like below.           
> Dim otr As mshtml.IHTMLElementCollection = GetCurrentWebDoc.getElementsByTagName("table")
> 
> But a web page related to the above web site (http://206.222.29.162/winners.jsp), I do lot of manipulation using your example codes.
> Advance thanks.


Kumartech,

that site is a bit odd, in that it uses a single frame page. So getting the current web doc using the function in my code simply returns the frames page, and not the frame document itself. So you can use this code, to grab the frame, and then grab the document from that frame.



```
        Dim mainFrame As mshtml.HTMLWindow2 = DirectCast(GetCurrentWebDoc.frames.item(0), mshtml.HTMLWindow2)
        Dim CurrentWebDoc As mshtml.HTMLDocument = DirectCast(mainFrame.document, mshtml.HTMLDocument)
```

----------


## healthpro

I am trying to automate a process that involves repetitive access to a website after loggins on.

I have downloaded and reviewed the kleinma example and I am having trouble just getting started.

I am getting the error message

Message	"Unable to cast object of type 'System.Windows.Forms.HtmlDocument' to type 'mshtml.HTMLDocument'."	String

in the GetCurrentWebDoc function.


My code is just getting started but is posted below...

Public Class Form3

    Private Sub Form3_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        wb.Navigate("http://www.njmmis.com/login.aspx")
    End Sub

    'FILLS THE HTML TEXTBOX WITH TEXT FROM OUR WINFORM
    Private Sub SetTextboxText(ByVal Text As String)
        DirectCast(GetCurrentWebForm.item("txtBox"), mshtml.HTMLInputElement).value = Text
    End Sub

    'ALL THIS FUNCTION DOES IS GRABS THE CURRENT DOCUMENT FROM THE WEBBROWSER CONTROL
    'AND CONVERTS IT TO THE STRONG TYPED mshtml.HTMLDocument CLASS
    'THIS SAVES CODE BECAUSE YOU NEED TO GET THE WEB DOC FOR ALL CASES OF MANIPULATION
    Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
        Try
            Return DirectCast(wb.Document, mshtml.HTMLDocument)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

    'SAME AS THE ABOVE FUNCTION, EXCEPT IT GRABS A WEBFORM. I ASSUME HERE THERE IS ONLY 1 FORM
    'IF YOU WERE DEALING WITH A PAGE WITH MULTIPLE FORMS, SIMPLY USE ITS INDEX (THEY ARE IN AN ARRAY)
    'THIS IS A USEFUL METHOD BECAUSE OFTEN TIMES WHEN MANIPULATING A WEBPAGE, ITS TO GET/SET DATA IN A FORM
    Private Function GetCurrentWebForm() As mshtml.HTMLFormElement
        Try
            If GetCurrentWebDoc.forms.length > 0 Then
                Return DirectCast(GetCurrentWebDoc.forms.item(0), mshtml.HTMLFormElement)
            Else
                Return Nothing
            End If
        Catch ex As Exception
            Return Nothing
        End Try
    End Function

Private Sub Button1_Click( ByVal sender As System.Object,  ByVal e As System.EventArgs) Handles Button1.Click
    DirectCast(GetCurrentWebForm.item("txtUserName"), mshtml.HTMLInputElement).value = "xxxxxxxl"
End Sub
End Class

Any direction would be most appreciated.
I am using VS2005.

Thanks, 
~Ken

----------


## kleinma

My example code using the COM based webbrowser control. Prior to VS2005 there was no built in webbrowser control in the toolbox. So you had to use the COM one.

I am actually in the process of retooling this sample here to be exclusive with the 2005 managed browser control (well slightly extended) instead of the COM based one, but its going to have to wait until I finish up a few important projects.

----------


## healthpro

Matt, 

What am I missing?

I thought I was using the com based control.
I included a reference to the Microsoft Internet Control 1.1.0.0 COm object.

I even copied the actual control on the window from the sample code.

----------


## kleinma

what line of code exactly gives you the error?

----------


## jabberwock

i'm having problems getting the source code of a site that i navigated to with the webbrowser

i get this error "Object reference not set to an instance of an object."

on this line F.txtSource.Text = GetCurrentWebDoc.documentElement.outerHTML

----------


## kleinma

that error just means something is evaluating to null (nothing)

either GetCurrentWebDoc, documentElement, or outerHTML is equal to nothing when you call that. Figuring out which one, would be the first step to getting it working.

Since you didn't give the actual URL, I can't really advise any further.

----------


## rocky20

Hi!
In your example i see that you get the value from combo box
But i need to set value in combo box how can i do that?
thank for answer

----------


## kleinma

To set a combobox, you can either set the selectedindex value of it to the desired index you want, or you can set the value to whatever value you want

Obviously either the selectedindex or the value has to be a valid one (ie you can't specify a value that doesn't exist in the list)

Also remember that a value is NOT the same thing as what is displayed in a combobox.

Combobox HTML code looks like


```
<select id=cmboSelect>
<option value=""></option>
<option value="a">Apples</option>
<option value="o">Oranges</option>
</select>
```

so if you wanted to set Apples you would need to set the value of the combo to "a"

----------


## rocky20

i would like to set both text displayed and the value. Is this even possible?
I would like to pass somekind array of parameters
something like
ParamName=value
so i was thinking that ParaName can be Value in combobox and the Value of param Could be the textdisplayed  of combobox.Cause i only need this to pass data.

SO is there any other chances or possibilities to pass that kind of data, combobox would be great cause i have more than 1 parameter and i would not like to parse string in textbox

----------


## kleinma

if you don't know the value, and only know the text you want to set, you need to loop through the "options" elements inside the select element until you find the one thats innertext value matches what you want, and then set that option as the selected option

----------


## rocky20

i know both in my program paramName and value
Can you give me any example for VB6, on how to do that!
I acees to textbox like this WebBrowser1.document.GetElementById("txtPrintFormName").Value
so how can i access to combobox

----------


## kleinma

it should be the same way, but using the combobox name instead of the textbox name.

I haven't coded in VB6 for a few years now, so I am not sure if there is anything additional to consider. As you probably know, this entire thread is focused on VB.NET

----------


## rocky20

Hi!
This is how it goes set the combobox in  VB6
WebBrowser1.Document.GetElementById("DropDParam").Options(0).Text = "hmmmmmmmmmmmmmmmmmmmmmmmmmmm"
WebBrowser1.Document.GetElementById("DropDParam").Options(0).Value = "123"

But now i have another problem, when i click my go button on page
(code click event in my webpage)
String text = DropDParam.Items[0].Text;
 it takes the default value from combobox, not the value i set in vb6 webbrowser control
i also must include this in web.config   <pages enableEventValidation="false"/>
if i don't when i click on button it give me next error:

_Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.  For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them.  If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation._

----------


## d.j.t

Hi i'm quite a noob, and what i want to do is extract a table from http://www.handelsblatt.com/News/def...ymbol=FLUK.NWX and save it as xls or txt. when i tried your project i recieved an error: " Name 'GetCurrentWebForm' is not declared ".

so why this error?
and where exactly do i find the code to extract?
and how do i save that to a file?
finally: how do i click a link ("weiter" at the bottom right of the table)

(hope i didnt ask something that has already been answered)
well, thanks in advance!

----------


## katanshin

I'm having severe difficulties with a slightly more exotic (but similar) issue...

If anyone's able to shed some light, please let me know here:
http://www.vbforums.com/showthread.p...36#post3078736

----------


## RJ_Palkar

This has been a great learning tool. 
Thanks a lot. 
I also have the similar problem. 
I want to enter the username and password into a form which is a Citrix MetraFrame XP page. 
basically it's a Citrix page which gives access to some other box but we want to use Windows Credentials rather than citrix username/password. So what we are trying to do is, having a middle layer (vb.net app) which will load the citrix page behind the scenes. After authenticating with the windows credentials of the User, the page will fill in the citrix username/password and hit the login button. 
I tried your code and the application you have provided (WebPageManipulation) but it falls over at GetCurrentWebForm function. 
I investigated and found that Document Object doesn't have any forms in it or probably it's increpted. (i'm not sure) but the Document.Forms.Length always returns 0. 
I have attached the file with this thread.
please take a look at it.

thanks
RJ

----------


## kleinma

RJ,

That MHT file was not viewable in IE, however I did look at the source and there is defenitly a form there.

Its name is 3DNFuseForm.

Without seeing workable source, it is hard for me to really advise further.

Are you sure that there are no frames being used?

----------


## JFitz

Hi Kleinma,

I've been looking through everything here and didn't see an answer to my question below, or I missed it somewhere.

I have a link I want to click but it has no id or tagname. It does have a 'href' and so in order to click it I want to try to loop through the links until I get my one using the code below.



```
For Each element As HtmlElement In WebBrowser.Document.Links
            If element.GetAttribute("href").Contains("Call_Detail_Records") Then
               element.InvokeMember("Click")
               Exit For
            End If
         Next
```

Problem is that when it's looping it loops through the other links on the page but doesn't loop through the the three links in the centre of the page so it never reaches the call detail records link. By reading this forum my guess might be that it is in it's own form or something like that?

I am using IE Developer Toolbar to look at the webpages so that I can see what the id's, tag names etc are and it is very useful. But, it doesn't seem to allow me to identify forms, or at least I haven't figured that out yet. So, my question is, how can I know what forms are on the page? And secondly, why did the link I was looking for not get included in the WebBrowser.Document.Links object?

Thanks, JF  :wave:

----------


## kleinma

the fact that a given link may be inside a set of <form> tags should not exclude it from the links collection. However if the page has frames or some other structure to it, then that can cause the issue.

First thing to do is identify if infact this is a frameset page or not..

----------


## JFitz

Thanks, sorry I said forms earlier, but I meant frames... I'm not sure how to identify the frames on a page... (I am using IE Developer toolbar to identify all the other elements but can't see the frames).

If I right click on the area in IE and go to 'view source' I can of course see the html (below), but I don't see any frame tags exactly, there is a mention of myiframe, is this this the frame (what's the best way to idenify a frame - sorry I don't know much about this!)... 



```
<html>
<head>
<title>Billing</title>
<META http-equiv='Content-Type' content='text/html; charset=UTF-8'>
<link rel="stylesheet" type="text/css" href="/ivechangedthis.css">
<script language='JavaScript'>
function dyniframesize()
{
  if (document.getElementById)
  {
     //begin resizing iframe procedure
     var dyniframe = window.parent.document.getElementById('myiframe');
     var newHeight = 800;
```

----------


## kleinma

the easiest way to determine actual frames is using the IE dev toolbar like you mention you have.

the webbrowsers document property is the highest level document in the page. In the case of a frames page, this document generally has little more than the outline of how each individual frame will be displayed (ie where it will show up) and also what the source URL is for each frame.

Being that each frame has its own URL, it also has its own document. So EACH frame contains a document object, and that is where the HTML you want to get at is.

Now if you know the framenumber (by index) or the frame name/id (if it has one) then you can access frames by those values. If not, you can also loop all frames, and inside that loop, loop all links in each frames document.

it would look like this:




```
        'LOOP ALL FRAMES OF THE MAIN DOCUMENT
        For Each frameWindow As HtmlWindow In WebBrowser1.Document.Window.Frames
            'LOOP EACH LINK IN THE CURRENT FRAME
            For Each element As HtmlElement In frameWindow.Document.Links
                If element.GetAttribute("href").Contains("Call_Detail_Records") Then
                    element.InvokeMember("Click")
                    Exit For
                End If
            Next
        Next
```

note that the exit for that is called only will exit the inner loop. You might want to put this code in its own subroutine so you can call exit sub once the link is found and clicked, to avoid the routine looking through the rest of the page when it does not have to.

See this screenshot. I found a random frames page example on the web, then using the IE dev toolbar, I can see that the main document is a frameset, and has 2 frames, and you can see each frame has its own document object which we can access.

----------


## JFitz

That's excellent. That worked. But why it worked is still a puzzle. 

When I only use the code inner loop (For Each element As HtmlElement In WebBrowser.Document.Links) then, as I say, the three links in the centre of the page (which are perhaps in another frame) are skipped.

Now, when I include your outer loop and loop the frames (For Each frameWindow As HtmlWindow In WebBrowser.Document.Window.Frames) the three links in the centre of the page are now included in the inner loop BUT it looks as though there is only one frame because the outer loop only does one pass (there is no second framewindow to loop).

Does that make any sense to you? By looping the frames, the three central links were included (whereas before they weren't) but it still appears that there is only one frame as the outer loop only does 1 iteration. Why does the code work? 

Comparing the html from the ie developer toolbar there is only 

<HTML>
   <HEAD>
   <BODY>

and no mention of framesets, so I'm getting the impression there is only one frame on this webpage? Well, either way it works now so it's not a problem but I'd be interestd to know what's going on there?

Thanks a bunch!

JF  :Big Grin:

----------


## kleinma

even if there is only one frame, the page will still have the frameset page, and then the encapsulated frame which has the HTML you want to get at.

So it makes sense that it works with my outer loop even when there is only 1.

Without that loop of the frames pages, you are still only looking in the main document, which has nothing but information about the frame that will fill up the window.

----------


## JFitz

Ah ok great.

Can you help me with one final question, eh, well can I be greedy and ask for two!?  :Embarrassment:  

I remember reading somewhere here the mention of being able to gain control of a pop up window but don't remember seeing how to do it. I have a window which pops up and loads some text. I then want to save this as a .html file. Can I do it?

And also, I have scoured the web trying to find out how to do a 'save target as', you know, instead of simply clicking a link and bringing up an IE dialog box prompting whether you want to save or not, I would like to simulate a right click 'save target as' event so I can save straight onto my hard drive. Is it possible? I get the feeling it probably isn't?

Thanks for you help! JF  :Alien Frog:

----------


## ed08724

kleinma:
I have tried your example and it seems to work in VB2008 but if I start from scratch and just copy in your code for a button to my project it doesn't work it seems to have something to do with the windows form genertated code. The error I get is on the 3 webBrowser.Document.forms.item(, 0) lines and the error is overload resolution failed because no accessible 'Item' accepts this number of arguments. How do I make it generate the windows form code for my own project?
Also I tried using a URL of https://www.harrahs.com/MyHarrahs.do with:
webBrowser.Document.forms.item(, 0).elements("accountId").value = "15701390709"
webBrowser.Document.forms.item(, 0).elements("pin").value = "1234"
webBrowser.Document.forms.item(, 0).submit()
but it comes back with a totally blank page instead of an error page, the ID and password are fake, or the correct status page with correct login info.

My code that generates the error is:
Imports System.Web
Public Class Form1
    Inherits System.Windows.Forms.Form
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Navigate("https://www.harrahs.com/MyHarrahs.do")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        WebBrowser1.Document.Forms.Item(, 0).elements("accountId").value = "1234567"
        WebBrowser1.Document.Forms.Item(, 0).elements("pin").value = "1234"
        WebBrowser1.Document.Forms.Item(, 0).submit()
    End Sub

End Class

----------


## akagi07

here is my html sample
I'm trying to simulator automate filling of data to the webBrowser:
<html>
<head>
<form name="input" action="html_form_action.asp" method="get">
Username: <input type="text" name="user">
<br><input type="radio" name="sex" value="male"> Male
<br><input type="radio" name="sex" value="female"> Female
<br><input type="checkbox" name="vehicle" value="Bike">I have a bike
<br><input type="checkbox" name="vehicle" value="Car">I have a car
<br><input type="checkbox" name="vehicle" value="Airplane">I have an airplane
<br><input type="submit" value="Submit">
</form>
</head>
</html>

using vs2005, vb.net
FwebBrowser.Document.GetElementById("sex").SetAttribute("Gender", "male")
FwebBrowser.Document.GetElementById("vehicle").SetAttribute("Cartype", "Bike")

I had resolved text boxes, button click events, drop down list but coming to radio buttons and checkbox, I failed.

I couldn't understand how do I set the rdo btn o chkbox to "checked"
can someone guide me

----------


## whoa99

I have a little bit of a problem. I did not see that it was covered previously, if it was I apologize.

I am attempting to create a password manager that automatically saves username and password information from a web page and fills it back in when you revisit the same web page. My dilemma is accurately finding the "User Name" element and "Password" element for each web page. Since every page can have different names, tag-names, etc.

I have been playing around with a couple of different methods, sometimes they work, with some pages that have multiple "input" elements and I cannot correctly identify the correct elements. My thought process so far has been to find an element on the page whos type is "password", then find the element right before that that is a standard "input". Does anyone know if there is a way to get this information, and fill it back in accurately with any web page?

This is the source code that I am playing around with right now. Any ideas? Thanks.

       HTMLDoc = iE7.Document
        iHTMLCol = HTMLDoc.getElementsByTagName("input")

        For Each iHTMLEle In iHTMLCol
            If Not LCase(iHTMLEle.type) = "hidden" Then
                Debug.Print(iHTMLEle.name & " [" & iHTMLEle.type & "]")
                Debug.Print(iHTMLEle.value)
                Debug.Print("")
            End If


            'For iForm = HTMLDoc.forms.length - 1 To 0 Step -1
            'For iElem = HTMLDoc.forms.item(, iForm).elements.length - 1 To 0 Step -1
            'Debug.Print(HTMLDoc.forms.item(, iForm).elements.item(, iElem).type)
            'If HTMLDoc.forms.item(, iForm).elements.item(, iElem).type = "password" Then _
            'HTMLDoc.forms.item(, iForm).elements.item(, iElem).value = "password"

            'If HTMLDoc.forms.item(, iForm).elements.item(, iElem).type = "input" Then
            'HTMLDoc.forms.item(, iForm).elements.item(, iElem).value = "User Name"
            'End If
            'Next iElem
            'Next iForm
        Next

----------


## ed08724

I tried the paypal example and it worked fine with paypal but my form at https://www.harrahs.com/TotalRewards/Login does not have IDs only names. How can I get it to work w/o the IDs?
Thanks for any help.

----------


## kleinma

ok guys. I have been real busy recently, so I wanted to just let you know I will address your questions individually soon when I have some free time.

I also plan on doing a full port of this code including some changes and enhancements over to 2008 pretty soon.

----------


## ed08724

I got my previous example w/o IDs to work with the following code but I can not figure how to click the Sign In button. Could someone please check the source code from the website https://www.harrahs.com/MyHarrahs.do and let me know how I can click the Sign In button. Just doing a submit for the whole form does not work.
Thanks.

For Each element As HtmlElement In WebBrowser1.Document.GetElementsByTagName("input")
   If element.GetAttribute("name") = "accountId" Then element.SetAttribute("value", "157013907069")
   If element.GetAttribute("name") = "pin" Then element.SetAttribute("value", "1234")
Next

----------


## ed08724

Nevermind. I solved it.

----------


## akagi07

> here is my html sample
> I'm trying to simulator automate filling of data to the webBrowser:
> <html>
> <head>
> <form name="input" action="html_form_action.asp" method="get">
> Username: <input type="text" name="user">
> <br><input type="radio" name="sex" value="male"> Male
> <br><input type="radio" name="sex" value="female"> Female
> <br><input type="checkbox" name="vehicle" value="Bike">I have a bike
> ...


still having troubles with setting values to rdobtn and checkbox..
can someone advise.

----------


## kleinma

> still having troubles with setting values to rdobtn and checkbox..
> can someone advise.


Because your have elements all named the same thing (vehicle and sex) there is no way to simply grab one like you are doing and set a value. Trying to grab just one will just give you the first matching element. You need to grab them all, and loop them until you are on the element you want, then take action on it.

Radio buttons and Checkboxes often have the same name or id properties, so this is approach needed often when dealing with these.

First I use this subroutine to check/uncheck a radio or checkbox.



```
    Private Sub ToggleHTMLCheckOrRadio(ByVal Checked As Boolean, ByVal CheckboxOrRadio As HtmlElement)
        Try
            If Checked Then
                If Not Convert.ToBoolean(CheckboxOrRadio.GetAttribute("checked")) Then
                    CheckboxOrRadio.InvokeMember("click")
                End If
            Else
                If Convert.ToBoolean(CheckboxOrRadio.GetAttribute("checked")) Then
                    CheckboxOrRadio.InvokeMember("click")
                End If
            End If
        Catch ex As Exception
            MessageBox.Show("Error occured toggling checkbox/radio: " & ex.Message)
        End Try
    End Sub
```

Then you need to call this code like so:



```
        For Each RadioButton As HtmlElement In WebBrowser1.Document.All.GetElementsByName("sex")
            If RadioButton.GetAttribute("value") = "male" Then
                ToggleHTMLCheckOrRadio(True, RadioButton)
                Exit For
            End If
        Next

        For Each RadioButton As HtmlElement In WebBrowser1.Document.All.GetElementsByName("vehicle")
            If RadioButton.GetAttribute("value") = "Bike" Then
                ToggleHTMLCheckOrRadio(True, RadioButton)
                Exit For
            End If
        Next
```

Notice how I grab all elements that match the given name/id. Then I loop them till I find the one with the correct value. Once I find that, I pass that element to the routine to check the checkbox or select the radio by invoking a click on it as if the mouse has clicked it.

----------


## kleinma

Did anyone else still need help with something here?

----------


## whoa99

I was still hoping you might be able to help me find an efficient way to find someone who entered a username and password in a form, so I could save only that data. The problem is I want it to work for any web page, so the element names might be never be the same.

----------


## akagi07

> Did anyone else still need help with something here?


Thanks for the guide. I will try tt out.

you mentioned abt the radio buttons. so which what i understand in my method, in order to check the right rdobtn, i had to call for a loop to test which btn value is selected then after toggling the radiobtn checked property.

But I had this ?
but for vehicles, thats checkbox. issnt checkbox diff from radiobtn? since checkbox allow multiple checked.. means the same thing, i had to test for which checkbox's value is chosen then toggle for the method to tick the checkbox for me?

----------


## akagi07

alright thank you alright!!!
my problem resolved.. but I had an array question new up..

##page link
localhost

#input type, name, button
text,user,testing123
password,password,password
checkbox,vehicle,Bike
radio,sex,male
---------------------VB CODE---------------------
'conversion
strContent = contentText.Text 'text to var strContent
strLine = Split(strContent, vbNewLine) 'breaking line by line

For Each line As String In strLine
If (line.Length = 0) Then
'empty line do nothing
ElseIf (line(0) = "#" And line(1) = "#") Then
'check for page link
ElseIf (line(0) = "#") Then
'capture as normal
ElseIf (Fdelimiter = True) Then
'page link
Else
strField = line.Split(",")
For Each word As String In strField
FstatusBox.AppendText(word & vbNewLine)
Next
End If
Next line

--------------------------------------------------------
i had declared strLine() and strField() as String array at start
and in the 2 For loops, I had strLine to store line and strField to store word

but for strField, I actually intended to append every new words extract from each line so this array will grow longer however in my above method, its only in size of 3, 0 1 2. every next line it goes, the var word will be overwritten.

I tried ways like dim strFD() as String = {word}, same too.

Any advise how can I add in new values of var word everytime into the string array instead of overwriting it?

SOrry, more advise required,  :Smilie:

----------


## akagi07

nvm thanks
I found a way..  :Wink:

----------


## rubiks cube

> Did anyone else still need help with something here?


Yep, I w8 for you to make the programm for vb 2008 :Smilie:

----------


## kleinma

> Yep, I w8 for you to make the programm for vb 2008


It will be done shortly and it will actually use the managed .NET browser control which will make the entire process easier.

----------


## Forgath

Hi,

I'm using WebBrowser object in .NET with good success for the most part, but run into some problems with what appears to be on-the-fly-altered content.  When I use webBrowser.Navigate("javascript**:__doPostBack(...)") from one webpage, some contents of the webpage change (as it is intended to do), but DocumentCompleted is not fired off when done.  Nor does webBrowser.Document nor webBrowser.DocumentText contain the new contents that have been inserted.  Even "View Source" via right-clicking in the control shows the old content and no sign of the new content.
Similarly, if one uses something like webBrowser.Document.ExecCommand("ForeColor", false, "#FF0033") while having some text highlighted, the content of the webpage is actually altered, but again does not appear to be reflected with Document or DocumentText.

Is there some other property or method to get at a truer representation of the current controls/state/etc in the WebBrowser?  Or perhaps some other way to at least easily intercept the data returned after the postback?

(The example I'm using with this kind of on-the-fly update is the Facebook Knighthood app's various info paging mechanisms http://apps.facebook.com/knighthood/)

Thanks

----------


## Delicioso

Hey
In VB.NET 2008 I have a WebBrowser with a web page that contains a comboBox.
I need to retrieve datas from that comboBox and set them into another comboBox in my VB.NET form, but i didnt manage to set values from the original combobox into an array.
I tried something like SlumberMachine :



```
 Dim MyHTMLCombo As mshtml.HTMLSelectElement = DirectCast(GetCurrentWebForm.item("choice"), mshtml.HTMLSelectElement)

        Dim total As Integer
        total = MyHTMLCombo.length

        Dim i As Integer
        Dim listvalue() as string
        For i = 0 To total
            MyHTMLCombo.selectedIndex = i
            listvalue(i) = MyHTMLCombo.value(i)
        Next
```

But this is for previous .NET versions and doesnt work in 2008.

I tried something else :



```
Dim MyHTMLCombo As HtmlElement
        MyHTMLCombo = (WebBrowser1.Document.GetElementById("Choice"))
        Dim test As String
        test = MyHTMLCombo.GetAttribute("value")
```

But test returns only the 1st element of the combobox....

----------


## Delicioso

I make a new post to make it clearer :
I found a way to retrieve values from a combobox in a WebBrowser with VB.NET 2008.
Here is an example with the google translation page (http://www.google.fr/language_tools?hl=fr)
We will retrieve values from the 1st combobox and set them into our ComboBox1.

Start a new project, insert a WebBrowser, a Button and a ComboBox in your form.



```
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate("http://www.google.fr/language_tools?hl=fr")
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        'The ID of the 1st ComboBox in the google translation page = sl, and we retrieve the HTML code for that comboBox into a string.
        Dim Values As String = WebBrowser1.Document.GetElementById("sl").InnerHtml

        'We will split each original value into a string array
        Dim myTab() As String

        myTab = Split(Values, "<OPTION value=")

        'We remove "OPTION value=" in each line, and each value now looks like : "value>text user see in the combobox</OPTION>"
        'Example : EN>English</OPTION>
        Dim i As Integer
        For i = 0 To UBound(myTab)

            'We throw away the </OPTION> from each line
            'Each Line looks like : "value>text user see in the combobox"
            'Example : EN>English
            myTab(i) = Replace(myTab(i), "</OPTION>", "")
            If myTab(i) <> "" Then
                
                'Now all we want to keep is the VALUE : we keep the left part of the ">" symbol in each line
                myTab(i) = Strings.Left(myTab(i), InStr(myTab(i), ">") - 1)
                ComboBox1.Items.Add(myTab(i))
            End If
        Next
    End Sub
End Class
```

----------


## M1A1_Abrams

I have a VB.net 2005 program that logs into a Web form and submits it. That part is working perfectly, my thanks to all on this forum for your posts. Without your posts, I would have been stuck. 

My question now is how do you determine a second or third document complete event? For example, my application logs a user into a Web site that uses frames and happens to be a java server page.

I used the navigate method to go to the main form. Then I used the document complete event to begin looping through the frameset which is a  method posted in another reply by Kleinma to loop through the frames and enter the log on information.

The Web site then returns another set of forms that I need to populate and submit. I am having difficulty with figuring out how to determine the best way to determine when each page load is completed so that I can begin passing the parameters to each form. Any ideas?

----------


## akagi07

hi any pros.

after many many tries, i came to this question..
vb webBrowser is a container, i load a webpage thru this webBrowser, means this page source is now inside the container.

is it possible to retrieve the x-y or the left location of the button in the html doc? I will need to know this, so that i can draw out an x-y location to get my cursor move to it.



```
For Each button In FwebBrowser.Document.All
                        If button.GetAttribute("value") = strInData(n + 2) Then
                            button.InvokeMember("Click")
                            FstatusBox.AppendText(button.ClientRectangle.ToString)
                            FstatusBox.AppendText(strInData(n + 2) & " button is clicked " & vbNewLine)
                        End If
                    Next
```

i tried the above, it gave me a result of {X=3,Y=3,Width=55,Height=18}
i supposed thats the x and y, but why 3,3?

i know that inside vb itself, i can use something like button.left to retrieve some info.

can any realli really help me out on this?

----------


## M1A1_Abrams

Any ideas on how to set the value in a combo box? I solved my earlier problem but am now stuck again. I tried using the Web manipulation project but keep getting an error. It does not not like it when it tries to cast my web form into an html document. Is there a way to set the value without having to do the cast? Thanks in advance.

----------


## BlayzeX

I recently tried to autofill in a form that did not have a name nor ID.. just FORM ACTION.....

normally I would use

vb Code:
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
        If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            WebBrowser1.Document.Forms("FORM NAME").All("OBJECT NAME").SetAttribute("value", "THE VALUE I WANTED")
            WebBrowser1.Document.Forms("FORM NAME").InvokeMember("submit")
        End If
    End Sub

This however didn't work.  So after messing around and I'm sure many people know, but for those who don't.. this worked...


vb Code:
Private Sub WebBrowser1_ProgressChanged(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserProgressChangedEventArgs) Handles WebBrowser1.ProgressChanged
        If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            WebBrowser1.Document.All("OBJECT NAME").SetAttribute("value", "VALUE I WANT")
            WebBrowser1.Document.Forms(0).InvokeMember("submit")
        End If
    End Sub

I am using the WebBrowser 2.0 standard located in VB 2008.  I tried Forms(,0) and did not work... i also tried GetelementbyID("OBJECT ID").invokemember("submit") but it didnt' work.. not sure why, but the obove code worked..

Hope it helps those who need it.. if not then just skim by this post...

----------


## M1A1_Abrams

Thanks for the response. I may try this when I get a chance. I had already solved the previous issues. I'm now working on the invokeScript method to call some Javascript functions. I have a new set of issues now. For one, I have the invokeScript method inside of a document completed event, which fires a Javascript function to select a tab on a Web form in order to go to the next page. However, that fires the document completed event, which triggers my invokeScript method...and so on, and infinate loop if you will. I'm trying to figure out the most graceful way of handling that. The other issue has to do with three text field for inputting a telephone number in the following format XXX XXX XXXX. The Web form designer named all three input boxes the same "TEL_" so, no matter what I try, the first three digits populate accross all three fields. The only unique attribute that I can find is the tab order. Any one have any ideas for these two issues?

----------


## Pac_741

Hi to all, im trying to use the hightlight function for my own application but im getting errors :

this its the code i use



```

    Private Function SelectText(ByVal Text As String) As Boolean
        Dim mydoc As mshtml.HTMLDocument = Getcurrentpage()
        Dim MyRange As mshtml.IHTMLTxtRange = Nothing
        MyRange = DirectCast(mydoc.selection().createRange, mshtml.IHTMLTxtRange)
        If MyRange.findText(Text) Then
            MyRange.select()
            Return True
        Else
            Return False
        End If
    End Function
    Private Function Getcurrentpage() As mshtml.HTMLDocument
        Try
            Return DirectCast(Applicationhelper.CurrentBrowser.Document, mshtml.HTMLDocument)

        Catch ex As Exception
            Return Nothing
        End Try
    End Function
   
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        SelectText(Searchtxt.Text)
    End Sub
```

----------


## Pac_741

does anyone know whats wrong with that ?? im using a normal webbrowser control, i dont know whats wrong........

----------


## Pac_741

i was playing with the project that kleinma uploaded, at the form load event 
i changed this code :



```
  wb.Navigate(Application.StartupPath & "\TestPage.htm")
```

to 


```
wb.Navigate("www.google.com")
```

and the search code didnt work, all the functions didnt work .....this doesnt work with webpages on the net ?? i would like to talk more about this with someone sooo....please help me

----------


## dhanraj

Hi Kleinma,

By using the SHDocVw.dll iam trying to browse the web page from windows application.

following is the code

Dim sWs As New SHDocVw.ShellWindows
         For Each ie In sWs
            doc = ie.Document

            If (ie.Document.GetType.ToString.ToLower = "mshtml.htmldocumentclass") Or (Microsoft.VisualBasic.Information.TypeName(ie.Document) = "HTMLDocument") Then
               url = CType(doc, mshtml.HTMLDocument).url

                If InStr(url, "something") > 0 Then
                    urlPostBack = url
                    iePostback = ie
                End If
            End If
        Next

I want to refresh the web page after navigating from windows application
which Iam trying to do in the following method.

Private Sub Endwork()
              If (par1 <> "") Then
                    iePostback.Navigate2(urlPostBack)
                End If
            End If
         End Sub

if i click on button on the web page It fires the windows application exe and does something and needs to refresh the web page again.For the first time it happens and If i click  for second time data is not updating.
I dont want to use ie.refresh2().
Please help me out

----------


## M1A1_Abrams

So this is what I've come up with....


```
Imports System
Imports System.Windows.Forms
Imports System.Security.Permissions


<PermissionSet(SecurityAction.Demand, Name:="FullTrust")> _
Public Class Form1
    Inherits Form

    Public Sub New()
        InitializeComponent()
        WebBrowser1.Navigate("https://****.***.com/***.jsp")
        AddHandler WebBrowser1.DocumentCompleted, AddressOf WebBrowser1_DocumentCompleted
    End Sub
    Private Sub webBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
        If e.Url.Equals(WebBrowser1.Url) Then

            'THIS CLASS LOGS INTO THE WEB INTERFACE

            'LOOP ALL FRAMES OF THE MAIN DOCUMENT
            For Each frameWindow As HtmlWindow In WebBrowser1.Document.Window.Frames

                'LOOP EACH ELEMENT IN THE CURRENT FRAME
                For Each element As HtmlElement In frameWindow.Document.GetElementsByTagName("input")
                    Select Case element.Name
                        Case "userId"
                            'enter some data into the input field
                            element.InnerText = "username"
                        Case "userPwd"
                            element.InnerText = "password"

                            For Each cboElement As HtmlElement In frameWindow.Document.GetElementsByTagName("select")
                                Dim controlName As String = cboElement.GetAttribute("name").ToString
                                If controlName = "dataCenter" Then
                                    'Stop
                                    For i As Integer = 0 To cboElement.Children.Count - 1
                                        If cboElement.Children(i).InnerText = "05 SomeItem" Then
                                            'Stop
                                            cboElement.SetAttribute("selectedIndex", i.ToString())
                                            Exit For

                                        End If
                                    Next
                                End If
                            Next

                        Case "login"
                            element.InvokeMember("click")

                    End Select

                    For Each cboElement As HtmlElement In frameWindow.Document.GetElementsByTagName("select")
                        Dim controlID As String = cboElement.GetAttribute("id").ToString
                        If controlID = "STATE" Then
                            For i As Integer = 0 To cboElement.Children.Count - 1
                                If cboElement.Children(i).InnerText = "South" Then

                                    cboElement.SetAttribute("selectedIndex", i.ToString())
                                    Exit For

                                End If
                            Next

                        ElseIf controlID = "PRIORITY" Then
                            For i As Integer = 0 To cboElement.Children.Count - 1
                                If cboElement.Children(i).InnerText = "Normal response time" Then
                                    cboElement.SetAttribute("selectedIndex", i.ToString())
                                    Exit For

                                End If
                            Next

                        End If
                    Next

                    'Because the DocumentCompleted event fires each time that a page loads,
                    'I am adding the Select Case for each form to this event handler
                    'This Select Case handles the "General Information" tab
                    Select Case element.Id
                        Case "Number"
                            element.InnerText = "NO"
                        Case "ITEM"
                            element.InnerText = "ITM"
                        Case "INITIALS"
                            element.InnerText = "INI"
                        Case "CALLER"
                            element.InnerText = "Caller"
                        Case "TEL_"
                            If element.GetAttribute("tabIndex").Equals("25") Then
                                'Stop
                                element.InnerText = "NPA"
                            End If
                            If element.GetAttribute("tabIndex").Equals("26") Then
                                'Stop
                                element.InnerText = "NXX"
                            End If
                            If element.GetAttribute("tabIndex").Equals("27") Then
                                'Stop
                                element.InnerText = "XXXX"
                            End If

                        Case "TBL_LOC"
                            element.InnerText = "TRBL"
                        Case "CENTER"
                            element.InnerText = "Center"

                    End Select


                Next
            Next

        End If
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'If element.GetAttribute("value").Equals("Save/Update") Then
        'frameWindow.Document.InvokeScript("submitMainNew", New Object() {"F5"})
        'End If

        For Each frameWindow As HtmlWindow In WebBrowser1.Document.Window.Frames
            'Need to add this to the onClick event of the SC app - works
            If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
                frameWindow.Document.InvokeScript("selectScreenTab", New Object() {"Problem Information"})
            End If

            For Each txtElement As HtmlElement In frameWindow.Document.GetElementsByTagName("textarea")

                Select txtElement.Id
                    Case "ADD_OPENING_REMARKS"

                        txtElement.SetAttribute("value", "hello! I suppose the problem could be that my text string isn't long enough. Heck, it's worth a try")

                End Select
            Next

            'For Each element As HtmlElement In frameWindow.Document.GetElementsByTagName("input")
            'Select Case element.Id
            '   Case "SYSMSG"

            'Dim sysMsg As String
            'sysMsg = element.GetAttribute("value")
            'MsgBox(sysMsg)

            'If MsgBoxResult.Ok Then
            'Me.Dispose()
            'End If
            'End Select
            'Next

        Next
    End Sub

End Class
```

This code logs into a Web site on my company's Intranet and manipulates everything except for the textarea....or does it? 

Here is a code snipet of the textarea that I'm having trouble with...


```
<div class="TTextScrollArea" id="ADD_OPENING_REMARKS0" style="position:absolute; left:15; top:443;"><textarea tabindex="40" name="fieldValue" id="ADD_OPENING_REMARKS" class="fieldValue" rows="4" cols="34" maxlength="800"></textarea>
      <input type=hidden name="fieldName" value="Add Opening Remarks">
      <input type=hidden name="fieldInstance" value="0">
      <input type=hidden name="fieldOldValue" value="">
      <input type=hidden name="fieldServerValue" value=""></div>
<div class="TLabel" id="ADD_OPENING_REMARKS" style="position:absolute; left:15; top:429;">Add Opening Remarks</div>
```

When I watch this program run in the debug window, it acts like it populates the textarea. The innerText, innerHTML, and value tags all reflect my sample text. However, when I look at the Web form itself, the textarea is still empty. I look at the source code of the Web page inside of my WebBrowser control but the value of my sample text is not there. The textbox values that I set show up though.

I've tried everything that I could find on this and other forums without any luck. So the question is, should the text show up when I set the values through code? I tried just logging into the site manually and filling out the form myself. When I typed text into the textarea and did a view source on it, the text wasn't there either. So I'm confused. Is that normal behavior? Does my solution work? I can't test the values inserted into the database yet because the person that maintains it won't let me see the data I pass. It is a highly restrictive environment, nothing that I can do about it. He also controls the Web form so I can't change it either.

Any suggestions? Hopefully my code will help others or at least put them on the right path. I'm new to VB.NET using VS 2008. If any of the more advanced users see a more graceful or efficient way to redesign my code, please post your suggestions. I am eager to learn all that I can. Thanks in advance for your help.

----------


## M1A1_Abrams

I finally figured out the TextArea issue, really simple actually. Thanks again to Klienma for posting the looping code for frames. That really had me stumped for awhile. Good luck to the rest of you with your questions.

----------


## razohad

hi,

I am codding am email client based on Gmail.
i can login the inbox just fine but i need to enable there pop mail forwarding
and i just cant find a way.
I do know that there have a frames in there webmail and thats it.
oh wait baiscly the url is http://mail.google.com/mail/?hl=iw#settings/fwdandpop onxe you're loged in your gmail account .



plz help me i am totaly lost.

thanks

----------


## razohad

nevermind that i found its frame name and i can check the radio button
but now i have a difrrent problem....(as allways).

the "save changes button"is diabled unlees i click the radio button manualy.

is there a way to submit it even if its disabled?

in ie developer toolbar i see that it has an Attribute "Disabled = -1"
and a readonly  Attribute "isdiabled= true"

and when i check the radio button manualy it changes
the readonly  Attribute "isdiabled= false" and i cant see the Attribute "Disabled" anymore.

thanks a head

----------


## razohad

anyone here??

----------


## Amsterdam

I have a webpage that I need to automate a button click.  I've already logged in and navigated to the link on the website.  When a product becomes available, there will be an 'Accept' link that I need to click. Its first come first serve so the link is hardly ever there.  I was planning on polling this page and refreshing if I cant find the link.  I see this in the page source.  How can I search for the Accept Order and click the link if its present?

<td>
							<span spry:choose="spry:choose" >
								<span spry:when="'{EVENTTRACKINGID}' == '0'" >Order Accepted by Another Agent</span>								
								<span spry:when="'{EVENTTRACKINGID}' == '1'" >Congratulations, this order is now in your <a href="/index.cfm?event=VendorsOnly.getOpenEvents&person_&event_type=form,form_html,rfi">Workflow</a></span>
								<span spry:when="'{EVENTTRACKINGID}' > 999" ><a href="index.cfm?event=VendorsOnly.bpoPostingBoardAccept&eventTrackingID={EVENTTRACKINGID}" class="arial10blue">*Accept Order*</a></span>
							</span>
						</td>



Would it be easier to just move the mouse and click in an x,y coordinate area?  I know an approx area of where this button will be located.

thx,

Amsterdam

----------


## kleinma

if you guys give me a few days, I am actually working on completing a new version of this webbrowser interface, that hopefully will make things a bit easier.

----------


## kleinma

> I have a webpage that I need to automate a button click.  I've already logged in and navigated to the link on the website.  When a product becomes available, there will be an 'Accept' link that I need to click. Its first come first serve so the link is hardly ever there.  I was planning on polling this page and refreshing if I cant find the link.  I see this in the page source.  How can I search for the Accept Order and click the link if its present?
> 
> <td>
> 							<span spry:choose="spry:choose" >
> 								<span spry:when="'{EVENTTRACKINGID}' == '0'" >Order Accepted by Another Agent</span>								
> 								<span spry:when="'{EVENTTRACKINGID}' == '1'" >Congratulations, this order is now in your <a href="/index.cfm?event=VendorsOnly.getOpenEvents&person_&event_type=form,form_html,rfi">Workflow</a></span>
> 								<span spry:when="'{EVENTTRACKINGID}' > 999" ><a href="index.cfm?event=VendorsOnly.bpoPostingBoardAccept&eventTrackingID={EVENTTRACKINGID}" class="arial10blue">*Accept Order*</a></span>
> 							</span>
> 						</td>
> ...


loop all the links (anchor tags) looking for one that has the href value you are looking for, or has the inner text of "Accept Order" that you are looking for.

Once you find that, you will have the HTML anchor element, and you can invoke click on it.

----------


## razohad

kleinma 

can you plz help with my problem
i posted 4 posts above

thanks

----------


## JuggaloBrotha

kleinma, you should mark your thread here as Resolved.  I've seen just about every question on here asked two or three times each.  If future people can't bother to read the solution to their problem on page 3, 4, 5, etc then they should probably not bother trying to use your code correctly.

Just my opinion.

----------


## kleinma

Well this is the code bank, so we tend to not mark threads resolved here, however this particular thread has gained a good amount of interest since I wrote it originally.

Infact, I don't even use the COM based browser anymore, as I was able to extend the managed one and add in what the COM browser had that made me stick with it for a while (basically adding back in NewWindow2 and NavigateError events of the browser)

However I agree with you on the points that most of this is getting redundant, as I have answered frames questions for people before, and I simply DO NOT have the time these days to answer everyones individual question with regards to specific webpages they are trying to automate. This code was provided as a "proof of concept" and of course does not cover all scenarios on the web, and people need to take my code and figure SOME stuff out for themselves. This isn't a magic black box you can just wire up to a webpage and get full automation. Since the web is sort of like the "jungle", its very wild and you have millions of webpages that were all built with different tools using different technologies, etc....

I have done some automation projects inhouse and via consulting, and every single time, the projects specs were totally different because the site we were automating always has its weird quirks to it.

So that being said, I am officially stating my responses will be somewhat limited in this thread beyond what I have already assisted with. I am working on a 100% managed browser version of this demo with even more features built in, which I will likely make available for free on my website, as well as the codebank here.

----------


## razohad

so did i mis the train.

i didnt find anything on pages 1-8 about enabling a diabled button.

i guess i'll have to look somewhere else :<

----------


## kleinma

enabling a disabled button will likely have weird effects on any "well written" website.

Usually they disable a button on a site because they DONT want you to click it. So usually there is also server side code in place to make sure no code is executed if the button state should be disabled, regardless of its actual state on the webpage. This is because they should take into account that JS might not be enabled on the client, so they need to do all validation checks server side as well.

In any event, setting a disabled button to enabled is as easy as referencing the button element in question, and setting its "disabled" property to false. My example code shows how to grab a textbox and set its text property, so that should be sufficient information for you to figure out how to grab a button and set its disabled property, right?

----------


## razohad

first let me say thanks for the reply.




> that should be sufficient information for you to figure out how to grab a button and set its disabled property


thats what i figured but it does'nt work.

my code is


```
 Dim theElementCollection As HtmlElementCollection = WebBrowser1.Document.Window.Frames("canvas_frame").Document.Body.GetElementsByTagName("button")
        For Each curElement As HtmlElement In theElementCollection
            Dim controlName As String = curElement.GetAttribute("value").ToString
            If controlName = "Save Changes" Then
                curElement.SetAttribute("disabled", False)
            End If
        Next
        Dim theElementCollection1 As HtmlElementCollection = WebBrowser1.Document.Window.Frames("canvas_frame").Document.Body.GetElementsByTagName("button")
        For Each curElement As HtmlElement In theElementCollection1
            Dim controlName As String = curElement.GetAttribute("value").ToString
            If controlName = "Save Changes" Then
                curElement.InvokeMember("click")
            End If
        Next
```

but no go any idea?

----------


## kleinma

I was thinking about it. disabled doesn't really get set to false or true, the actual HTML syntax is just the word disabled inside an input element.

like

<input id="txtName" disabled/>

I think I have seen disabled=disabled or disabled=true in HTML and I think it just works because of the word disabled is there and that's enough for the parser.

I think what the MSHTML parser does in this case, is if you set the disabled attribute of an element, it adds the disabled attribute and thats enough for the browser control. The value doesn't matter at all.

So this would disable it



```
curElement.SetAttribute("disabled", "kleinma")
```

and when you want to remove this specific attribute, you pass an empty string, which enables the control



```
curElement.SetAttribute("disabled", "")
```

----------


## razohad

once again your right.  :Smilie: 

this work


```
curElement.SetAttribute("disabled", "")
```

but after i remove the disabled attribute 
and click the button it doesnt do anything.

any idea why?


p.s kleinma your my hero .

----------


## kleinma

yes, well as I said before, there is generally more validation going on that just the disabling of the button. Simply disabling a button is not very secure, really just more of a visual aid to prevent the average joe from multiple clicks while waiting for a round trip of a webpage.

imagine a website where you disabling certain buttons that access features someone needs to pay for to have access to. now imagine someone could just enable the button with some javascript and access these features. That wouldn't be very smart on the part of the web developer.

----------


## razohad

ok thanks i get the idea.

----------


## Ranex

Hello kleinma,

Can i get some help from you?
I am new at vs2005 but have some old programing experiance (Clipper,Enz)  :Smilie: 
i have made a nice website (ASP) with login's for some friends.
A friend showed me VS2005 and Yes that's where i wanna put some time in :P

But you guest right i run in to some problems, after looking on the internet for some day's i found you posts  :Smilie: 



```
Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
        Dim Varemail = "fake@fake.nl"
        Dim Varpassword = "fakepassword"
        WebBrowser.Document.Forms.Item(, 0).elements("email").value = Varemail.text
        WebBrowser.Document.Forms.Item(, 0).elements("password").value = Varpassword.password
        WebBrowser.Document.Forms.Item(, 0).submit()
End Sub
```

Oke the problem : i can't try this because VB2005 say's about this  line's: 

```
WebBrowser.Document.Forms.Item(, 0)
```

Error	1	Overload resolution failed because no accessible 'Item' accepts this number of arguments.
I can't find the solluntion  :Sick:  

The code of the website and the Before asp page i made.



```
<!-- Loginlayer -->
	<form action="login2e.php" method="post" name="login">
		<td>email1</td><input class="editbox" name="email2" id="email3" type=text style='width: 190px;'>
		<td>password1</td><input class="editbox" name="password2" id="password3" type=password style='width: 190px;'>
		<td>Lock this sessie</td><input type=checkbox name="lock-session" id="lock-session" checked="checked">
		
<!-- Loginbutton -->
		<input type="image" src="buttons.php?pid=1&l=153&t=317&w=100&h=22&m=LOGIN">
	</form>
```

	For this form i just: (ASP)



```
Response.Write("<FORM Target='2escreen' method='post' Action='http://www.fake.nl/fake/login2e.php'>")
    Response.Write("<INPUT Name='email' value='fake@fake.nl' type='hidden'>")
    Response.Write("<INPUT Name='password' value='fakepassword' type='hidden'>")
    Response.Write("<INPUT Name='submit' type='image' src='../../pix/Login2e.gif' width='18' height='15' id='submit'>")
    Response.Write("</FORM></TD>")
```

maybe you can help me with the code ?
Regards Ranex

----------


## kleinma

try this:

WebBrowser.Document.Forms.Item(0)

the managed version of the browser control doesn't take 2 params, which is normally either a string name of the item, or the collection index of the item. It only takes the index, so you only use 1 parameter.

----------


## at133

I initially wrote some code for clicking a button on a website.  It no longer works.  Here is the code for the button I would like to click.


```
<input type="button" class="blackbutton" onclick="editorAjax(this,'preview=0&amp;key=440632');" id="editor_submit" value="Submit Text" />
```

I think in the past when it worked the input type was different.  Now when I use 

```
WebBrowser1.Document.GetElementById("editor_submit").InvokeMember("click")
```

 nothing happens.  I also tried invoking the script with


```
Dim ObjArr(2) As Object
ObjArr(0) = CObj(New String("editor_submit"))
ObjArr(1) = CObj(New String("preview=0&amp;key=440632"))
WebBrowser1.Document.InvokeScript("editorAjax", ObjArr)
```

 in the document completed event.  Nothing seems to work.  The button is not part of a form, it is simply an input.  Any ideas on how to make this work?

Thanks

----------


## kleinma

Do you have a specific URL?

The first line should work, unless there is something else going on behind the scenes with the ajax stuff.

The second thing you tried may not work because you are passing the ID of the button as the argument to the JS routine, however its really expecting the object reference of "this". So I am not sure if the JS will do a translation there.

Anyway, if you have a specific URL I can probably take a look at it, if you can't provide one, then I probably can't help too much.

----------


## at133

I figured it out.  The problem was with my computer.  I transferred the code to a different one and now it works perfectly.  I don't know what changed but now on that box visual basic will no longer interact with button in the webbrowser.  Thanks for the reply.

----------


## kleinma

I would check the specific version of IE on each machine. If they are different by any stretch, it could be that is the reason.

----------


## Ranex

vb Code:
Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
        Dim Varemail = "fake@fake.nl"
        Dim Varpassword = "fakepassword"
        WebBrowser.Document.Forms.Item(0).elements("email").value = Varemail.text
        WebBrowser.Document.Forms.Item(0).elements("password").value = Varpassword.password
        WebBrowser.Document.Forms.Item(0).submit()
End Sub

This doesn't work either, 
i start to doubt if it's possibly to post data to a form with webbrowser control :Frown:

----------


## kleinma

> vb Code:
> Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
        Dim Varemail = "fake@fake.nl"
        Dim Varpassword = "fakepassword"
        WebBrowser.Document.Forms.Item(0).elements("email").value = Varemail.text
        WebBrowser.Document.Forms.Item(0).elements("password").value = Varpassword.password
        WebBrowser.Document.Forms.Item(0).submit()
End Sub
> 
> This doesn't work either, 
> i start to doubt if it's possibly to post data to a form with webbrowser control


what browser control are you using? The COM one, or the .NET managed one? I am not sure where you are getting that code, but it doesn't look like it came from my example.

----------


## Ranex

Hi Kleinma,

I am using the .net from VB 2005 Webbrowser control,
mayby you can take a closer look at post  #293 there is al the code and in post #294 you replayed to that one, there is also the form where i want to post the data  :Smilie: 

[Respect]

----------


## kleinma

does it do anything at all when your code runs?

You are doing 3 things in your code, filling in 2 textbox fields, and clicking 1 button.

So do any of those occur? or simply nothing occurs?

----------


## Ranex

This is what intelligence say when i typed those 3 lines:
Error 1 Overload resolution failed because no accessible 'Item' accepts this number of arguments.

----------


## kleinma

if you are using the managed browser control (the .NET one built into .NET 2.0 and up), I would think your code should look like this:



```
        WebBrowser1.Document.Forms(0).All("email").SetAttribute("value", "fake@fake.nl")
        WebBrowser1.Document.Forms(0).All("password").SetAttribute("value", "fakepassword")
        WebBrowser1.Document.Forms(0).InvokeMember("submit")
```

----------


## Ranex

Nice great, looking for this for weeks now. 
Already got a bill from www.Google.com  :Smilie: 

I still get a error but basics works.
the email and login are posted than the login is activated,
on the second page there is en age question witch olso has a submite buttom
after giving the age answere (Manual) VB gave this error: Object reference not set to an instance of an object. ON LINE: WebBrowser1.Document.Forms(0).All("email").SetAttribute("value", "fake@fake.nl")

Very strange.

But still lot's of thanks.
[Respect]

----------


## kleinma

well if its asking an age question, why is the field you are referencing called "email" still???

Also make sure that it is the FIRST form on the page. If there are more than 1 form, you need to use another index instead of 0 (or you can reference the form by its actual string name if it has one)

----------


## Ranex

They strange thing is that i am already login and showing the seconde page i also entered the age value en clicked the next button as the error occors.
This is the code:


```
Private Sub
        WebBrowser1.Document.Forms(0).All("email").SetAttribute("value", "fake@fake.nl")
        WebBrowser1.Document.Forms(0).All("password").SetAttribute("value", "fakepassword")
        WebBrowser1.Document.Forms(0).InvokeMember("submit")
End Sub
```

It looks to me that the sub is already ended because those 3 line's of code already done there thing  :Smilie: 
No there is no email on the seconde page.
I will keep looking and trying  :Smilie:

----------


## kleinma

where are you calling this code from? The DocumentCompleted event?

----------


## chaosfactory

hi kleinma, i know ur very busy but i've lookd at ur manipulate html program and it's helped me a lot up until now. i'm trying to grab some data from a text box and also click a submit button but the problem i'm having is that they are embedded in  a table and  the html code looks  like this :



> <td>
>     <form action="do.php" method="post"><input type="hidden" name="fb_sig_time" value="1212024219.9303" /><input type="hidden" name="fb_sig_added" value="1" /><input type="hidden" name="fb_sig_user" value="" /><input type="hidden" name="fb_sig_profile_update_time" value="1211595353" /><input type="hidden" name="fb_sig_session_key" value="3e0cbd386d76f1163cf3c180-277622" /><input type="hidden" name="fb_sig_expires" value="0" /><input type="hidden" name="fb_sig_api_key" value="afe4c25ae28531b4785fe2a9a34fd1fb" /><input type="hidden" name="fb_sig" value="9047b3ba4d47016bb5dfcdcf7364c06d" />
>     Deposit Amount: <input type="text" name="deposit_amount" value="0" />
>     <input type="hidden" name="action" value="deposit" />
>     <input type="submit" value="Deposit" />
>     </form>
>     <p class="note">A 10% safehouse fee will be taken out of all incoming funds.</p>
>   </td>
> </tr>
> </table>


i'm really trying to deal with the deposit amount. i need to be able to read whats in the text box and also click the submit button.
i've been using:
DirectCast(GetCurrentWebForm.item(), mshtml.HTMLInputElement).value but it doesn't seem to work in this case

----------


## kleinma

DirectCast(GetCurrentWebForm.item(), mshtml.HTMLInputElement).value 

This isn't even valid syntax. You aren't actually grabbing any specific item with this code..

----------


## chaosfactory

well for instance i used ur code for this:
DirectCast(GetCurrentWebForm.item("email"), mshtml.HTMLInputElement).value = emtxt.Text



> <label for="email" id="label_email">Email:</label><input type="text" class="inputtext" name="email" value="" id="email" size="20" onkeypress="login_form_change()" />


and that works for the login page but i don't know what to use for the above case because there are no id's and i'm not sure what to use in order to grab what i want.

----------


## chaosfactory

nevermind i figured it out  :Smilie:

----------


## Franklin

> if you guys give me a few days, I am actually working on completing a new version of this webbrowser interface, that hopefully will make things a bit easier.


Hey man,

I was wondering if the new version you spoke about above would be in VB2008? And if so, if you were close to releasing it?

Thanks for your time

----------


## chaosfactory

i have a question, how can i get the axwebbrowser control on a machine running xp? i've tried to reference the shdocvw.dll and it didn't do anything. i also tried to reference the two dll's from kleinma's webmanipulation project but still i can't get the control to show up when i go to chose toolbox items.

ugh, for some reason i always figure things out after i post it...

----------


## kleinma

> Hey man,
> 
> I was wondering if the new version you spoke about above would be in VB2008? And if so, if you were close to releasing it?
> 
> Thanks for your time


It is almost done. The project itself will be done in a 2008 solution/project, however I target the .NET 2.0 framework.

This is because there is no difference between the browser control in .NET 2.0 and .NET 3.x so by targetting 2.0, you maximize compatibility.

----------


## Franklin

> It is almost done. The project itself will be done in a 2008 solution/project, however I target the .NET 2.0 framework.
> 
> This is because there is no difference between the browser control in .NET 2.0 and .NET 3.x so by targetting 2.0, you maximize compatibility.


Thank you for the info and the fast response. I look forward to seeing it greatly  :Smilie:

----------


## razohad

any idea where i can find example of
 filling a form  using httprequest code?

----------


## elpive

> any idea where i can find example of
>  filling a form  using httprequest code?


Hi razohad, i have no idea about this but perhaps you could help me.

Can you give some orientation about activate POP3 forwarding on gmail settings from the vb .net code with the axwebbrowser.

I can create an account and log into but i can't check the POP3 radiobutton and saves the changes (the gmail code about it look so strange).

Can you help me? thanks a lot.

----------


## kleinma

> any idea where i can find example of
>  filling a form  using httprequest code?


You can't fill a form with an httprequest. You can however post data to a URL similar in a way that when you fill out an HTML form and click submit, the data is posted to the URL that is in the action attribute of the <form> tag. This also requires the method of the form tag is post, and not get, otherwise you would be dealing with querystrings and not form posts.

----------


## razohad

> You can't fill a form with an httprequest. You can however post data to a URL similar in a way that when you fill out an HTML form and click submit, the data is posted to the URL that is in the action attribute of the <form> tag. This also requires the method of the form tag is post, and not get, otherwise you would be dealing with querystrings and not form posts.


any idea where i can find an example ?

and thanks

----------


## elpive

> any idea where i can find an example ?
> 
> and thanks


I think that kleinma said something like:

<form name="input" action="html_form_action.jsp" method="post">
Username: 
<input type="text" name="user">
<input type="password" name="passwd">
<input type="submit" value="Submit">
</form>

then in the httprequest you must specifid the url:

"http://domain/html_form_action.jsp?user=" & user.text & "&password="  & password.text

----------


## kleinma

its a little more complicated than that, since the 

"http://domain/html_form_action.jsp?user=" & user.text & "&password=" & password.text

would be more like an HTTP GET operation versus an HTTP POST

HTTP POST encodes the values as a byte array and passes them, versus GET which uses a querystring attached to the end of the URL.

----------


## mannymd

I am using a WebBrowser control in a Windows form. I am able to login using the methods you specified in this thread. The probelm is that after loggin in, I need to click on a link where I can download and XML document. The WebBrowser modifies the XML document so that when I try to retrieve the XML document using "webBrowser.Document.Body.InnerText" I get the XML document but the WebBrowser control applied some transformation to it so that you can click on +/- to expand/hide sections. If I right click on the WebBrowser control and select view source, I get the XML document. How can I get the actual XML document?

----------


## kleinma

My example code has a method to get the source. Doesn't that do what you need?




> If I right click on the WebBrowser control and select view source, I get the XML document

----------


## mimang

Thanks Klient.. i reed your posting and try your sample, but i want to ask about if the html page contain a variable like this 

dim ImageFilename
function GoLoadImage()
   ImageFilename=""
   fg =AddPic1.LoadPic()
   if fg=0  then 
      ImageFilename=AddPic1.GetFileName()
      document.all("pimage").src=ImageFilename
   else
      alert("Image Error")
   end if
end function

can .NET set variable ImageFilename from textbox. 

thanks 
sorry my english bad i from indonesia

----------


## mimang

OK I have been solve my self 
to call variable I use 


vb Code:
WebBrowser1.Document.parentWindow.execScript "ImageFilename='D:\\MyDocument\\ody.jpg'", "vbscript"

just change "JScript" into "vbScript"

thanks all

----------


## scootabug

Hey Matt!

I have been busy searching around this topic of completing forms in web browsers.  This topic seems to focus on having the WebBrowser control in your application.

I'm wondering what you need to do to have the same functionality in a "3rd party application" window?  So say you have Internet Explorer or Firefox running, and your application also running...(system tray perhaps), what's the go with autofilling forms in a stand alone web browser?

Thanks mate!
Scott

----------


## elpive

> Hey Matt!
> 
> I have been busy searching around this topic of completing forms in web browsers.  This topic seems to focus on having the WebBrowser control in your application.
> 
> I'm wondering what you need to do to have the same functionality in a "3rd party application" window?  So say you have Internet Explorer or Firefox running, and your application also running...(system tray perhaps), what's the go with autofilling forms in a stand alone web browser?
> 
> Thanks mate!
> Scott


You can do it in a very simply form with javascript for example. Have you seen the greasemonkey addon in firefox?

----------


## scootabug

> You can do it in a very simply form with javascript for example. Have you seen the greasemonkey addon in firefox?


Thanks elpive.  While I am sure that would do what I am after, it's only handling part of the issue.  I want to have my dot net application hold a database of web sites and their associated logins.  I can't do that with Greasemonkey and I also need to handle any/all web browsers.

Surely there's a way to make my application, let's say it's running in the system tray and it's watching web browser windows (just like download managers are watching for a download to start) and detecting when a particular login page is detected and when it is, if the particular form exists (the login form) it can insert the username and password from my applications database once it has loaded.

I'm not sure what this particular process is called, so I'm not sure where to start looking.  Any suggestions?

----------


## Xancholy

Please can I request a VB2008 version ? trying to open the attached project generates errors:



```
[*]Warning	2	The referenced component 'Microsoft.mshtml' could not be found. 
	 [*]Warning	1	Could not resolve this reference. Could not locate the assembly "Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, 
PublicKeyToken=b03f5f7f11d50a3a". 
Check to make sure the assembly exists on disk. 
If this reference is required by your code, you may get compilation errors.	WebpageManipulation 
[*]Error	3	Type 'mshtml.HTMLDocument' is not defined.	C:\Documents and Settings\Administrator\Desktop\WebpageManipulation\WebpageManipulation\frmTest.vb	85	22	WebpageManipulation
```

----------


## kleinma

I started a 2008 version, like my other things, I just haven't finished it yet.

I had a bunch of new features lined up for it, but I suppose getting a mirror image of this current sample, but done in the managed browser control would be just as benefitial for the time being.

In any event, that error is just because you need that file. Try searching your hard drive for it, if you don't have it, let me know, and I can upload it here. I sort of thought I had done that in one of these previous replies already, but I don't have time to read back through 9 pages  :Wink:

----------


## Xancholy

No need to read 9! pages. I managed to find the missing file. That's great work. Thanks.

On a side note, you've shown us how to manipulate textboxes, checkboxes, etc..

What about autoclicking an image that does not use ahref ? eg:


```
<div class="iconbody">
<input id="ctl00_cp1_btnDownload" type="image" style="border-width: 0px;" onclick="openWindow('download','3pwBhzhigrk5PL4HGdAq2bDHDBlmHO0qkJvITXr5sRc1'); return false;" src="App_Themes/NA_Default/Images/Icon_Download.gif" name="ctl00$cp1$btnDownload"/>
```

How do I click image named ctl00$cp1$btnDownload ?

----------


## kleinma

you can either run its javascript function directly, or you can invoke a click event on it.

----------


## gmchun83

Hai,we would like thanks to kleinma that provide sample code to us for make our development more easy.But,we are having some issue about button.We have found most button at html pages that available at internet nowadays.Their don't provide id or name for button.At sample code,it only work for button when have id or name.Please refer following for the html code(submit button).




> <form method="GET" action="http://www.myweb.com/addurl.html">
>   <tr><td align=left><font face="helvetica,arial,sans-serif">
>   Url to add:<br>
>   <input type="text" name="url" size=30 value="http://"><br><br>
>   Your email address:<br>
>   <input type="text" name="email" size=30 value=""><br>
>   <input type="checkbox" name="optin" checked value="1"> Send me the newsletter<br><br>
> 
>   <input type="submit" value=" Submit URL ">
> ...


Please advice.
Thanks a lot.

----------


## razohad

> Hai,we would like thanks to kleinma that provide sample code to us for make our development more easy.
> But,we are having some issue about button.We have found most button at html pages that available at internet nowadays.
> Their don't provide id or name for button.
> At sample code,it only work for button when have id or name.Please refer following for the html code(submit button).


if i understand you correct then you can try this 


```
Dim theWElementCollection2 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("input")
        For Each curElement As HtmlElement In theWElementCollection
            Dim controlName As String = curElement.GetAttribute("type").ToString
            If controlName = "submit" Then
                curElement.InvokeMember("click")
            End If
        Next
```

----------


## tronni

Thanks for this great example. It’s working excellent.

I'm able to logon to my website and navigate to right page, but how can I download a file? (I want to download the file to a defined location ek: c:\tmp\file.txt)

The download dialog pops up after I click a button:

HTML: <input type="submit" name="pdirsall" value="Recursive" class="fatbuttom"/>

I've no idea where I should look. Can you help me please?

Thanks  :Smilie:  

Tronni

----------


## kleinma

if you can get the URL of the file to download, you can just download it directly using VB code. You don't need to automate anything on the part of the browser. Look at my sig for another example code on how to download files from the web with a progress bar. You could work that into your browser app.

----------


## tronni

Sorry, I forget to mention that, I don’t have a direct URL, if I had I could use your app or something simple like:

vb Code:
My.Computer.Network.DownloadFile("webURL", "downloadDestination")
Guess I must accept and handle the file stream from the webserver? Anyways I have no idea how I should do this (I have some experience with file streams).

Do you know a way to do this or where I can find some information?

Thanks for answering  :Smilie:

----------


## kleinma

the code that has the 

<input type="submit" name="pdirsall" value="Recursive" class="fatbuttom"/>

that input is obviously to submit a form. There isn't a field in the form, or the action value of the form tag, that indicates what file will be downloaded?

How does it know which file to download for you?

----------


## Mark107

kleinma, I want to fill the name first and the random numbers at the end (like from the start mark0 to the end mark1000) on the first textbox of the webpage. I want to do the same text what i did to the first textbox and the email address i want to input at the end like this mark0@fakemail.com so do the same to fill on the email address require box. I also want to click the tickbox, the program type the security code itself, click the webpage button and click my form button to go back and do the next random number like what I did first mark0 and do the second mark1.....It is bit like counting up so i want to keep going like loops until it stop 1000.



my register site:
http://mark107.awardspace.com/register.php



I'd appreciate it if you get what i mean from my description on above.  :Smilie:  lol



Hope you can post the code.


Thanks,
Mark

----------


## stlaural

Hi guys,

I have a web form which is already open in an IE Window. What I want to do is to fill two of its fields, respectively id = "df_1_0" and id = "df_2_1", with my VB.NET application.

So, First, I need the application to find the correct IE Window, access the two fields and fill them.

And, Second, The web page is using framesets and frames, the form is contained into one of the frames so I am not sure how I could access the fields by the VB.Net application. I don't think that I can use the WebBrowser Control because to get to the page that contains the form, I need to authenticate myself, and then on the page that I am redirected to I can open the form, which will open in an other IE Window (kinda popup).

So the real question is this : can I control an already opened IE window and access its components ?

thanks for helping !

----------


## kleinma

the only reliable way to do that would be writing a plugin for IE. I am not sure if you can write IE plugins in .NET code, or if you have to use native C++ or something like that.

The other method would be using a cheap hack like sendkeys, which is totally unreliable.

----------


## Mark Douglas

Hi kleinma,

I've been successfully using your example here to pull a listing of hyperlinks off one of my Intranet pages for a basic listing of links.

Well i have like 100 web pages i would like to run the program on. However because .net cycles through the pages so fast, i don't think the pages are fully loading, and it just repeats the hyperlinks from the first web page 100 times.

Do you know if there is a way to execute some code once the page is fully re-freshed? So cycle through each ".htm" file, and once its finished totally loading, then run the hyperlink code. The code then pastes it into an excel sheet. Which i have working. Just not the wait for page load type thing?

Any ideas? Thank you for any help!!

So im using



```
  Strpath = "\\server\Intranet\Intranet\CAD Dept"
     

        For Each strdir In IO.Directory.GetFiles(Strpath, "*.htm", IO.SearchOption.TopDirectoryOnly)

            wb.Navigate(strdir)
      
            For Each MyLink As mshtml.HTMLAnchorElement In GetCurrentWebDoc.links
             
                Temp &= MyLink.href
                Wksht.Cells(MyrowNum, 8) = Temp
                i += 1
                MyrowNum = MyrowNum + 1
                Temp = ""
            Next
        Next
```

----------


## kleinma

use the documentcompleted event. That event fires when the page is fully loaded. In that event you can check the current URL to take specific action based on what page has just loaded.


Just also note it will fire more than once if the page is actually a frames page.

----------


## Mark Douglas

Seems like this is only fireing at the very end of the cycle of htm files. Only the 100th htm is accessing the documentcompleted code? 



```

        Strpath = "\\server\Intranet\Intranet\CAD Dept"

        For Each strdir In IO.Directory.GetFiles(Strpath, "*htm", IO.SearchOption.TopDirectoryOnly)

            wb.Navigate(strdir)


        Next
```

If just keeps cycling through each htm page and once its done, then the documentcompleted aspect fires?

----------


## kleinma

how are you accessing each page? My guess would be probably in some sort of loop, but that will not fit in to the asynchronous way the browser control works.

You need to initially fire off a navigation to the first htm page. Then documentcomplete will fire, then you do whatever you need to do with that page, and then navigate to the next url in your list, until its all done.

----------


## Mark Douglas

Ok here is how im accessing the files, and the looping. Basically looping the webpages, and hoping for the document complted code to fire after i navigate to each page. But isnt working like that. 

Im running VS2005 forgot to mention that if that helps?

Thanks for the help!!



```
   
    Dim Temp As String = String.Empty
    Dim myExcel As Excel.Application
    Dim MyrowNum As Integer = 1
    Dim i As Integer = 1
    Dim Strpath As String
    Dim strfile, strdir, strdir2 As String
    Dim Wksht As Excel.Worksheet

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        myExcel = CType(CreateObject("Excel.Application"), Excel.Application)
        Dim Owb As Excel.Workbook = myExcel.Workbooks.Add()
        myExcel.Visible = True
        Wksht = DirectCast(myExcel.Sheets("Sheet1"), Excel.Worksheet)
        Strpath = "\\server\Intranet\Intranet\CAD Dept"
        For Each strdir In IO.Directory.GetFiles(Strpath, "*htm", IO.SearchOption.TopDirectoryOnly)
            wb.Navigate(strdir)
        Next
            End Sub

    Private Sub wb_DocumentComplete(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles wb.DocumentComplete
        Wksht = DirectCast(myExcel.Sheets("Sheet1"), Excel.Worksheet)
        For Each MyLink As mshtml.HTMLAnchorElement In GetCurrentWebDoc.links
            Temp &= i.ToString & ")" & Environment.NewLine
            Temp &= MyLink.href
            Dim MyFileArray As Object
            MyFileArray = Split(Temp, "/")
            Dim MyArrayCount As Integer
            MyArrayCount = UBound(MyFileArray)
            Dim MyLinkFile As String = Replace(MyFileArray(MyArrayCount), ".dwf", "")
            Wksht.Cells(MyrowNum, 8) = MyLinkFile
            i += 1
            MyrowNum = MyrowNum + 1
            Temp = ""
        Next
    End Sub
```

----------


## kleinma

again, you can't call navigate in a loop like that. You can't hope 1 routine will fire before the other. Well I guess you can hope, but it just won't happen.

Rethink your logic a bit, and read what I wrote above as far as how you need to do this.

Create a listing of the URLs (in an array of list of string, whatever) that you want to nav too. Then kick it all off by navigating to the first URL, and ONLY the first URL. When DocumentComplete fires, do the code you are doing now, but when you are done, call the navigate method again (in documentcomplete) and navigate to the next URL, and so on... until you are done.

----------


## stlaural

Thanks for the quick answer kleinma, that confirms what I thought. I will have to use the SendKeys and try to make it as reliable as possible. Should be able to work a solution at 95% reliability. at least I hope so.

I'll make sure that the keyboard and mouse are locked during the process, which should only last 4 to 5 seconds.

thanks again

----------


## kleinma

I have heard (but not confirmed) issues with using SendKeys and Vista due to its more secure user account structure. You may want to check that out.

----------


## Mark Douglas

Hi kleinma, your solution on how to approach it worked, putting the page change in the document completed portion. Thanks!!

P.S. On the send keys in Vista, yes I'm working on another program right now that runs inside AutoCAD, and Vista wont let me sendkeys to it or any other program. Bummer...

Thanks for the help!!

Mark

----------


## kleinma

It is security to avoid a rouge program from being able to have access to another program. Like you enter your password in 1 program, and another program is monitoring it to steal it.

You may have success with SendKeys in Vista if both processes are running with admin rights, but I am not sure of that.

----------


## Mark107

@kleinma: Is it possible to get pass of the automatic captacha image??




Thanks,
Mark

----------


## kleinma

Nope.

----------


## swallowbob

Hi Kleinma,

How do emulate this button ? It has no id. DirectCast(GetCurrentWebForm.item("submit.add-to-cart", 0), mshtml.HTMLButtonElement).click() can not get anything. 

Thanks.

html:

<input type="image" src="images/G/01/x-locale/common/transparent-pixel._V42752373_.gif"  width="160" alt="Add to Shopping Cart" name="submit.add-to-cart" class="bbSprite btn-atc_s" height="27" border="0" />

----------


## kleinma

it doesn't look like a button to me.. it looks like an image..

----------


## swallowbob

It is a button. Can you help me take a look "Add to shoping cart button" on amazon? It should be a button. I suspect that I have to specify the form id since they have a lot of forms there.
thanks for your help.

----------


## kleinma

sorry, I was not fully clear.

It IS very much a button.

an HTML input elements type is determined by the type attribute. You posted

<input type="image" src="images/G/01/x-locale/common.....>

So it is an input element, of type image. It may feel like a button because you can click it and it does something, but that doesn't make it a button, so you can't cast it to a button element type from the MSHTML library, it simply isn't that type.

You should be able to cast it to an image element or a generic input element type, and then invoke a click on it to get the desired behavior. If you are unable to get a reference to it because it has no ID and you can't access it via the name property, then really the only solution is to loop all <input> elements in the DOM and evaluate their name property until you find the one named submit.add-to-cart, and then you would have your reference to the correct element.

----------


## swallowbob

Thanks, Kleinma

I got it work using the following method:
Dim thisObj As Object
        Dim butInput As mshtml.HTMLInputElement
        thisObj = webBrowser.Document.getElementsByTagName("input")
        For Each butInput In thisObj
            If butInput.name = "submit.add-to-cart" Then
                butInput.click()
            End If
        Next

Another question:
Can I hide the browser and still get everthing work? If I set visible to false, it can not get the same result as visible.

Thanks you give us very good example and help.

----------


## kleinma

Try setting the size of the browser very small, and then position it OFF the form by giving it negative x/y location settings (or x/y that are larger than the forms size). That should still allow it to technically be visible, even though you don't see it on screen.

----------


## swallowbob

Very good! It works. 

One last question, is there a good way to parse the price.
<td class="priceBlockLabelPrice">Price:</td>
    <td><b class="priceLarge">$26.05</b> 

Right now I loop block element and find class name priceLarge. It looks not very safe or stable.
Appreciate your help.

----------


## swallowbob

by the way, I have several operations, each click/submit wil take some time , the second operation is based the first operation result. In this case, how to avoid the second operation is too fast and doesn't run it if not get the first page result return. I tried sleep a while but looks like it will sleep the first operation too. multi-thread? thanks.

----------


## kleinma

no unfortunately, when you automate someone elses site, you are doing something they didnt intend or design for, so you get lots of cases where data you want doesn't have any easy way to access it other than some raw parsing. The downside is that when the page changes at all, it could break your parsing logic. However the same is true if they change something like an elements id value, which is generally considered the "easy way" to get data from a page.

As far as your question about timing, you need to use the documentcompleted event of the browser to do subsequent navigations and operations. This is the event that fires when a page fully loads into the browser and has been rendered. If you try to do ANYTHING to a webpage before this event fires, you will likely end up with an error sooner or later, because the page has not fully loaded.

So then people always ask the same question "well documentcompleted is only 1 event, and I need to do something different based on what page is actually loading", and the answer to that is you need to evaluate the browsers current URL when this event occurs, and that tells you which page just loaded, and you can take appropriate action from there.

Again, the process of manipulating webpages is a tricky one, and some sites are way easier than others. However I have done a few consulting projects and personal projects for web automation, and so far there was not a site I couldn't automate. Some projects require more maintenance than others, but that is just how it goes.

----------


## swallowbob

Thanks, Kleinma

You looks always online. What a great help!

I can imagine what we can not automate is the website you have to download a client(java program) on your computer.

----------


## kleinma

well yes, I was strictly speaking from an HTML/Javascript manipulation standpoint. Things like java applets and activex controls may have some automation capabilities, but it would be done totally different than the HTML manipulation.

----------


## swallowbob

Hi Kleinma,

Nice weekend. I met another problem.

When I submit a button, it works at most time but it will prompt a error dialog sometime which make it can not proceed. I have to click to close the dialog. What was I missing? Thanks a lot.

The error dialog is 
Title is Internet Explorer Script Error
An error has occurred in the script on this page.
Line: 72
Char: 1
Error: Invalid argument
Code: 0
URL: xxxx
Do you want to continue running scripts on this page?

Here is my code to submit:
        webBrowser.Document.forms.item(, 0).elements("twotabsearchtextbox").value = txtField1.Text
        'webBrowser.Document.forms.item(, 0).submit()


The following is the form html:
  <form style="width:100%; margin:0 0 0 0; border:0; padding:0 0 0 0;" method="get" action="/s/ref=nb_ss_vg" name="site-search">

    <table width="100%" border="0" cellpadding="0" cellspacing="0">
        <tr>
        <td class="navSearchLeft"><img src="transparent-pixel._V42752373_.gif" width="58px" alt="Search" height="38px" border="0" /></td>
        <td width="100" class="navSearchBar"><select name="url" class="searchSelect" title="Search in">
                <option value="search-alias=aps">xxx.com</option>
<option value="search-alias=videogames" selected="selected">Video Games</option>
<option value="search-alias=videogames-used">Used Video Games</option>
               </select></td>
          <td width="3px" class="navSearchBar">&nbsp;</td>
          <td class="navSearchBar" align='left'><input type="text" id="twotabsearchtextbox"  class="searchSelect" name="field-keywords" value="" size="50" title="Search for" style="width:100%; background-color: #FFF;" /></td>
          <td align="right" width="3px" class="navSearchBar">&nbsp;</td>
          <td width="25" align="left">
          <div id="navGoButton">
          <input type="image" src=transparent-pixel._V42752373_.gif alt="Go" id="navGoButtonPanel"
            onmouseover="shiftImage('navGoButtonPanel',0,-38,'navGoButton',2,1,1);" 
            onmouseout="shiftImage('navGoButtonPanel',0,0,'navGoButton',2,0,1);" 
            onfocus="shiftImage('navGoButtonPanel',0,-38,'navGoButton',2,1,1);" 
            onblur="shiftImage('navGoButtonPanel',0,0,'navGoButton',2,0,1);" />
           </div>
           </td>
      </tr>
    </table>
    </form></td>

----------


## tanjiunnyann

kleinma, I want to do an auto login using webbrowser, I already done the auto-fill username and password in the form, but the web site contain the verify code. How to get the verify code from the showing picture? Any idea?

The web site is : http://www.17mso.com

----------


## kleinma

that picture looks to be the equivelant of a captcha verification, so no, there is no way to get around a captcha, except to write some code that can exame the image and determine the characters from the image.

The whole point of sites putting captcha verification on them, is to prevent automation of their site. To force an actual person to be there filling in the form.

----------


## swallowbob

Hi Kleinma,

Can you help me take a look above #366 problem? I suspect I need setup some properties/add some parameters manually for the embedded browser since IE works ok.
thanks.

----------


## WHATAGOAL1

kleinma, many thanks for your superb tutorial, everything i know about html has been learnt from this thread

i am trying to automate tradeXfair.com*WITHOUT THE X, can login and progress to the main page, but then it becomes proper difficult, my first question

 is it true that if it is on the webpage it can be automated?

the parsing of the final webpage returns very little, i have managed to glean the info that there are 47 elements, cannot find id, name or any thing else about them, although theire are children, same again no info can be gleaned

anyway i tried invoke a click on the child, (not knowing which), and the website returned "HTTP 403 Forbidden, website declined to show page


while navigating to the page, i have noticed info regarding cursor position
could this be the reason for the decline?. is it possible the  website is checking the position of my cursor to stop automation?

----------


## dbuhid

Hi kleinma, First thanks for sharing all this. It's been really usefull. Im working on some automation on a site containing AJAX on some processes. The problem is when I analize html code (on pages with AJAX) because (.net 2008) webbrowser shows me source of original html page (the one that loaded first).
Is there any workarround to solve this? I need the html source code of updated page (after ajax's been executed).
I have tried 
wb.nabigate("javascript**:'<xmp>' + window.document.body.outerHTML + '</xmp>'") with no success, but curiosly it works fine when pasted on IE. Am I missing something?
Thanks again.
Ariel

----------


## dreadfear

Hi, thanks for the source you have provided but im going for something a bit different and i couldnt seem to figure out your src to well. I dont want a webbrowser, not one thats visible anyway but i want it to log into the website automatically with no actualy input from the user. apart from username and password



```
Public Class Form1
    Public Event DocumentCompleted As WebBrowserDocumentCompletedEventHandler
    Dim instance As WebBrowser
    Dim handler As WebBrowserDocumentCompletedEventHandler
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        AddHandler instance.DocumentCompleted, handler
        instance.Navigate("http://www.warez-bb.org/login.php")
    End Sub
    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
        .Document.Forms(0).All("username") = "dreadfear"
        instance.Document.Forms(0).All("username") = "*****"
        instance.Document.Forms(0).All("submit").Click()
    End Sub
End Class
```

I cant seem to place anything inside of the form boxes or get it to click submit, any help is greatly appreciated im having alot of troulbe with this.

Thanks in advance.

----------


## kleinma

just put the webbrowser control off the visible portion of the form. It needs to actually be visible for the automations to work (being visible and being able to see it don't have to be the same thing).

You could also do something like putting the webbrowser in a panel, and covering it with another control that is set docked to fill to cover over the browser control.

You usually do want SOME way for the user to be able to actually view the webpage, in the event automation fails for some reason, like the page doesn't load properly, it times out, it has changed and your automation no longer works, etc...

----------


## Taipei101

Hi, I have 2 questions.  I am tring to automate a file upload/download process and here is the html code:
    <input type="file" name="FileUpload1" id="FileUpload1">
    <input type="submit" name="btnUpload" value="Update" id="btnUpload">
1. The SetAttribute("value", "c:\file1.xls") does not work.  Which property should I use?
2. The submit button does two things - upload the specified file and then download another file, say file2.xls.  How do I catch the file2.xls?

Thanks!

----------


## dreadfear

> just put the webbrowser control off the visible portion of the form. It needs to actually be visible for the automations to work (being visible and being able to see it don't have to be the same thing).
> 
> You could also do something like putting the webbrowser in a panel, and covering it with another control that is set docked to fill to cover over the browser control.
> 
> You usually do want SOME way for the user to be able to actually view the webpage, in the event automation fails for some reason, like the page doesn't load properly, it times out, it has changed and your automation no longer works, etc...


Ok thats good but how do i actually get it to fill in forms or get it to click a button, i have no idea how to do that and no tutorial i find knows either, ive been searching for a long time  :Frown:

----------


## J. Jethro

Hello, I need help, I am using VB 2008

Here is what I want to do, first I want auto fill a textbox in my web browser and then submit it, and after that I want to retrieve data from the text on the web page and paste it into the textbox in my program,

----------


## Taipei101

> Ok thats good but how do i actually get it to fill in forms or get it to click a button, i have no idea how to do that and no tutorial i find knows either, ive been searching for a long time



I am struggling with the web automation for the last few weeks too.  Hope this would help.

dim mBrowserCompletedas boolean

Private sub Form_Load
    '--- open the web page and wait for it to finish
    mBrowserCompleted= false
    WebBrowser1.Navigate("www.mysite.com")
    WaitForBrowserToComplete()

    '--- enter all the fields
    webbrowser1.document.all("field1").SetAttribute("Value") = "abc"
    webbrowser1.document.all("field2").SetAttribute("Value") = "xyz"
    ...
    '--- submit the form and wait for the response
    mBrowserCompleted= false
    webbrowser1.document.Forms(0).InvokeMember("submit")
    WaitForBrowserToComplete

   '--- do whatever ...

end sub

Private sub WaitForBrowserToComplete()
    do
        application.DoEvents
    loop until mBrowserCompleted
end sub

Private sub Webbrowser1_DocumentCompleted(.......)...
    application.DoEvents
    mBrowserCompleted= True
end sub

----------


## Taipei101

> Hello, I need help, I am using VB 2008
> 
> Here is what I want to do, first I want auto fill a textbox in my web browser and then submit it, and after that I want to retrieve data from the text on the web page and paste it into the textbox in my program,



Take a look at my post( #377).  To retrieve data from the text on the web page and paste it into the textbox in your program:

txtField1.Text = Webbrowser1.document.all(field1").GetAttribute("Value").ToString()

...

----------


## Mark B

Well, I am not sure if this is where I need to post this but others sent me think ing it was so here I go.

   I have some info on a web page I want to put into my app I am making.

  I will show what I would most like to do but then end with any work arounds or things I might have to just settle with if it can be done at all ...

OK .... Here is the link to the web site http://www.tulsapolice.org/udsw.html

About middle way down you will see an area called Current calls ... this little box area contains the current police calls for my area .... oh by the way ... it refreshes every 60 seconds .. keep that in mind ...
   Within in this box area or frame or div or whatever you call it it contains two main peices of information
1. Description ie; Theft
2. Location ie; 123 Some Street Tulsa Ok

Ideally I would like to be able to get this updated info every 60 seconds and put it into my form/app displaying them in some control ... maybe a listbox or listview or perhaps just strait to an xml file .... dont matter just as long as its something I can access the info ....

Ok, I am not a web guru ... so maybe I am over looking the obvious and this info cant be accessed that way .. so ... how about option 2 then

Just grab the whole box/frame/div and display it in my app just like its seen on the page .... but .... get the updated info every 60 seconds ...

NOTE: This really doesnt allow me to do what I would most like ... as I am hoping to be able to access the info so I can keep record of what crimes are happening within certain areas ....

  Well, I hope I have explained good enough as to what I am hoping I can do ... so, can you point me in the right direction ....


Mark

----------


## kleinma

well the first thing to do when you want to automate a website or screen  scrape data from a site is look at the site source HTML to see what you are dealing with.

They are using ASP.NET it looks like, and that table is probably getting written out on the fly from the server, and unfortunatly, they don't attach any name or id attributes to the table tags for the data you want.

This doesn't make it impossible, just more of a pain because when you have some sort of unique attribute identifier, it makes it very easy to grab the specific elements of the DOM you want, and parse the data.

Instead, you have to do something like grab all the tables in the DOM, and find the table that has a TD with inner text containing "Current Calls". Then you know you have gotten the right table element, and you can parse it from there. Just keep in mind as soon as they decide to change the page at all, your code likely will break and need to be modified. That is the nature of automating someones website that has not designed their site with automation in mind.

----------


## Mark B

Yes, I looked at the source and it seems if I am looking at this right this is where it is all happening.


```
<div id="udecalls">
  <iframe name="UDSW" width="520" src="http://www.cityoftulsa.org/divisions/divisions.aspx?div=udsw" height="222"> Your browser does not support inline frames or is currently configured not to display inline frames.</iframe>

</div>
```

Its in an iframe within a div called udecalls ..... however the url itself seems interesting .... hmmm could it be this is what we are looking at being displayed int he iframe???
I will look into that and check it out.

  If so I may simply be able to display that but still this doesnt help me actually grab the info .. instead it would only let me display it ...

I will check out if I can display it but would love to be able to actually read it ...
Any thoughts will be appreciated 
Ill be back after I test the url

Mark

----------


## Mark B

Yep, this url http://www.cityoftulsa.org/divisions....aspx?div=udsw

Actually will allow me to display it on my app just as it is seen within the iframe.

However ..... could you give me any insight as to how I would actually display it on my app and how would tell my app to refresh it every 60 seconds?

Or point me to where I can find this out ...
Mean while I will do some searching on what control I will need ... thinking its webbrowser control ... but will reasearch it ... 

Be back later

Mark

Oh thanx for pointing me to the source code

----------


## Mark B

Ok I think I have this figured out ... well at least I have figured out that the info should be easily accessable ... I just dont know for sure how to parse this sort of info but let me give you an idea what I think then you can tell me where I am going wrong ...

 :Smilie: 

Ok this url http://www.cityoftulsa.org/divisions....aspx?div=udsw
It shoots the contents of what is in the frame that we are seeing on the page 

I simply put the url in my browser and wa la I can see exactly what is on their web page.
But can I get the info from it ... yes I would think it would not be so hard ... dont know how yet as I do not know how to parse this following info but here it goes...

First click on the url above and you will see the data I need to parse especially  if you view the source code of the above url
It will look like this ... this is actually a cut paste of the source code



```
<TABLE style="BORDER-RIGHT-STYLE: solid; BORDER-RIGHT-COLOR: black" cellSpacing="0" cellPadding="0"
				width="475" border="1">
				<TR>
					<TD style="FONT-WEIGHT: bold; FONT-SIZE: 14pt; COLOR: darkkhaki; FONT-STYLE: italic; FONT-FAMILY: Arial; BACKGROUND-COLOR: black"
						noWrap align="center"><FONT face="Times New Roman">Current Calls</FONT></TD>

				</TR>
				<TR style="FONT-WEIGHT: bolder; FONT-FAMILY: Arial" align="left">
					<TD style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: black; FONT-FAMILY: arial; BACKGROUND-COLOR: white">&nbsp;<FONT face="Times New Roman" size="3">Calls 
							Assigned to Officers</FONT></TD>
				</TR>
				<tr>
					<td style="BACKGROUND-COLOR: white"><table cellspacing="0" cellpadding="4" rules="all" border="4" id="dgCurrent" style="color:Black;background-color:White;border-color:Black;border-width:4px;border-style:None;font-family:Times New Roman;font-size:X-Small;width:475px;border-collapse:collapse;">
	<tr style="color:Black;background-color:White;font-family:Times New Roman;font-size:X-Small;font-weight:bold;">
		<td>Description</td><td>Location</td>

	</tr><tr style="color:Black;background-color:White;">
		<td>Traffic Stop</td><td>4800 S YALE AVE </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Traffic Stop</td><td>5200 S LEWIS AVE </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Traffic Stop</td><td>3400 E BAWB EXPY </td>

	</tr><tr style="color:Black;background-color:White;">
		<td>Non Injury Collision</td><td>FAIRGROUNDS @4100 E 21 ST S </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Robbery Alarm</td><td>2400 E 32 ST S </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Larceny</td><td>2000 E 81 ST S </td>

	</tr><tr style="color:Black;background-color:White;">
		<td>Larceny</td><td>7100 S SHERIDAN RD </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Pickup Found Property</td><td>5300 S YALE AVE #1100 </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Pickup Runaway Juvenile</td><td>1100 S FULTON AVE </td>

	</tr><tr style="color:Black;background-color:White;">
		<td>Suspect at Scene</td><td>3700 W 53 PL S </td>
	</tr><tr style="color:Black;background-color:White;">
		<td>Suspect in Custody</td><td>4100 S YALE AVE </td>
	</tr>
</table>
```

Sorry for it being so much ... but as you can see it shows the info I need to grab

Ok the question is ... how do I grab this source code from this url and then parse it for the needed info?

Any ideas anyone as to where I can see how to parse this ?

Mark

----------


## Mark B

Ok .... here is what I have tried so far I think I might be on the right track however this code is not pulling all the info into the string as I thought so I am obviously going about this the wrong way
heres the code I am using though maybe it will spark some ideas

As I simply want to parse the source or the url



```
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim strHtml As String
        strHtml = GetPageHtml("http://www.cityoftulsa.org/divisions/divisions.aspx?div=udsw/")
        rtbParse.Text = strHtml

    End Sub
    Public Function GetPageHtml(ByVal URL As String) As String
        Dim objWC As New System.Net.WebClient()
        Return New System.Text.UTF8Encoding().GetString(objWC.DownloadData(URL))


    End Function
```

Any thoughts?

Mark

----------


## saphox

....

----------


## Mark B

Ok I have done a lot of searching and playing with various code ... some of it I sort of get the idea of how it works and but find I do not yet understand it enough to over come some trouble s I am getting into ...

Ok ... you were right ... this is not going to be an easy task ... but its one I am not yet giving up on as I am getting close ... or at least feel I am ...

I though I would show what I have done ... what results I am getting and then just maybe you might point out how I can improve on it ..

Ok using link I found it would not parse the html because of &nsb < or something like that ... they had to be removed also it would not parse the metta data for some reason but if the two were removed from the html it parsed it just fine ...


So before I write code to remove them which I found some examples of who to do this ....

I decided to remove them myself and practice with the parsing side of the code ...
Here is the code and html being parsed .....


```
    Dim html = <html>
                       <head>
                           <title>Current UDSW calls</title>

                       </head>
                       <body>


                           <table style="border-right-style: solid; border-right-color: black;" border="1" cellpadding="0" cellspacing="0" width="475">
                               <tbody><tr>
                                   <td style="font-weight: bold; font-size: 14pt; color: darkkhaki; font-style: italic; font-family: Arial; background-color: black;" align="center" nowrap="nowrap"><font face="Times New Roman">Current Calls</font></td>
                                   </tr>


                                   <tr>
                                       <td style="background-color: white;"><table id="dgCurrent" style="border: 4px none Black; color: Black; background-color: White; font-family: Times New Roman; font-size: x-small; width: 475px; border-collapse: collapse;" border="4" cellpadding="4" cellspacing="0" rules="all">
                                           <tbody><tr style="color: Black; background-color: White; font-family: Times New Roman; font-size: x-small; font-weight: bold;">
                                               <td>Description</td><td>Location</td>

                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Non Injury Collision</td><td>6500 S YALE AVE </td>
                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Attempt to Serve Warrant</td><td>1200 S QUAKER AVE </td>
                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Burglary from Vehicle</td><td>4100 S YALE AVE </td>

                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Intoxicated Pedestrian</td><td>2500 W 47 ST S </td>
                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Fraud</td><td>4400 E 31 ST S </td>
                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Fraud</td><td>5900 E 56 ST S </td>

                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Hazard</td><td>1900 E 71 ST S </td>
                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Larceny</td><td>9500 S DELAWARE AVE </td>
                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Parking Violation</td><td>1900 S CINCINNATI AVE </td>

                                               </tr><tr style="color: Black; background-color: White;">
                                                   <td>Receive Information</td><td>SK-NIMITZ @3100 E 56 ST S </td>
                                               </tr>
                                           </tbody></table></td>
                                   </tr>
                                   <tr>
                                       <td id="TD1" style="background-color: white;" align="center">6 calls awaiting assignment</td>

                                   </tr>
                               </tbody></table>
                       </body>
                   </html>

'''' ............. Below is my code ....................

Dim tabString = From ts In html...<tbody>


        txt1.Text = tabString.Count()





        For i = 0 To 24
            ListBox1.Items.Add(tabString.<tr>.<td>(i).Value)

        Next
```

Ok here is what I am getting ....

Listbox fills with the data .... almost perfect ... almost is the operative word

Lets say the data in the fields above was this for example

<td>1</td><td>2</td><td>3</td><td>4</td><td>5</td><td>6</td>

When it pulls out the data and is loaded in the listbox the data should look lik this
1
2
3
4
5
6
Instead it looks like this
1
123456
2
1
2
3
4
5
6
Weird .....
But hey, it was cool, cause I at least parsed it LOL
I about did the Walter Brennan dance ....

Ok ... not sure how to fix this I have tried several dozen attempts with not much improvement

ALSO .... as you can see in the For statement I i as interger a value of  0 to 24
Its because I know there are at the moment 24 <td>Items with data in them</td>
..... I need to figure out hwo to count them or make go to end and stop or something like that
I tried to do 

```
 For i As Integer = 0 to tabString.count
```

BUT, the valu of tabString.count is only 2   which means its only counting up to 3 and stopping but if I remove tabString and just put i = 0 to 24 it will go right to the end and do what it is supposed to do ...

Any thoughts how I can clean this up and or a better approach

Please ... I really want to pull this off no matter how much work and learning I got to do ...

Mark

----------


## kleinma

Mark, I had time today to look at this for you finally.

Not sure exactly what you want to do with the data, but I did you up a quick parsing routine that will extract the data from the HTML and list it in 2 listboxes. You should be able to take this sample, and understand how to grab this data and do whatever you want with it.

So make a new WinForms project, and add a webbrowser control, and 2 listboxes

So you have Webbrowser1, Listbox1, Listbox2

Then paste this code into Form1



```
    Private _URL As String = "http://www.cityoftulsa.org/divisions/divisions.aspx?div=udsw"


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        WebBrowser1.Navigate(_URL)
    End Sub

    Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

        'GET CURRENT CALLS TABLE
        Dim myTable As HtmlElement = WebBrowser1.Document.All("dgCurrent")

        'MAKE SURE WE GOT A VALID TABLE OBJECT
        If myTable IsNot Nothing Then
            'LOOP ALL ROW ELEMENTS IN TABLE
            For Each MyElement As HtmlElement In myTable.GetElementsByTagName("TR")
                'THERE SHOULD BE 2 TD ELEMENTS PER ROW
                Dim myTDTags As HtmlElementCollection = MyElement.GetElementsByTagName("TD")

                'IF WE GOT 2 TD ELEMENTS, WRITE THEM TO 2 LISTBOXES
                If myTDTags.Count = 2 Then
                    ListBox1.Items.Add(myTDTags(0).InnerText)
                    ListBox2.Items.Add(myTDTags(1).InnerText)
                End If

            Next
        End If

    End Sub
```

run it and there you go  :Wink:

----------


## Mark B

WOW .......  :Big Grin:  


This works great ...........  Now I am going to go play with it a bit se if I can modify it to drop the webBrowser control

Which looks like I can ..... we will see but none the less this is absolutely marvelous

Thank you


Mark

----------


## kleinma

Worst case you could always set the browser to a very small size, and then set its location to a negative x/y value so its not actually visible on the form. I don't believe (can't remember off the top of my head) that the browser works properly if you just set its visible property to false. I have done projects where I simply cover over the browser control with a panel or something.

----------


## -Negative-

its full of errors with the "mshtml.*"
its all errors!!!

----------


## Mark B

Yes but I cant help the fact their web master well isn't a web master but I can say this code has been fantastic .... I am also learning now how to parse html with linq and LINQ is amazingly simple and powerful stuff. Again ... cant thank you enough for assisting me with this ... since this code ... seeing how to actually access the html has really just been awesome .... I have used this very code exampl to allow me to now get info from several pages ..

  Seeing it can be done has now as I said with LINQ to pull info and parse exact o specific info right from pages .... 

ANyway thank you ... I learn so much by example .. I really appreciate you taking the time

Mark

----------


## VisualBasic6

Many of the concepts can be used in VB6, however the specific .NET code will not be a simple copy/paste into VB6.

If you know .NET and VB6 you could probably easily port this code over to VB6

If I ever have some free time, maybe I will try, since you are the second person to ask in just a few days, but for now its really just .NET 2003/2005
__________________

Hi,

In the very first page you said you will provide Manipulated code for "WebpageManipulation.zip" in VB6 also.
I am trying to fill a textbox and conduct a search on http://www.fujitsu-siemens.ie/suppor...ranty_ent.html through excel VBA.
But not being successful.
Could you provide code in VB6 and help to solve this problem?

----------


## kleinma

I know both, but I don't have any plans to port this code over to an old language.

If anything, I will be updating this code for newer .NET versions.

----------


## cealagar

Hi there kleinma! I absolutely worship you after reading the entire thread and observe how good you are in programming. How I wish I could be like you someday.

Well here's what I wanna ask help for. I am migrating from VB6 to VB 2008 since I was able to get the copy of the program already. I am a newbie to Web Controls, and here's the favor that I wanna ask you of.

I have a Wordpress enabled blog and I made a program that will auto generate the content within VB. All I wanna do is to create a button that will automatically transfer the contents to the web control that I made.

Here's the source code of the .php page when posting a new content:
Whew... It was too long. I'll send it to you instead.

Sorry if it have to be really long. That is the contents of the "add new content" part. I can't ask too much by letting you do the entire job. I just want to know how will I be able to define the fields within this form and how can I manipulate/fill them out using VB? Including just the check boxes and radio buttons.

All I wanted to do is have my text fields' content transferred correspondingly. Then have it execute the "publish" button, validate if the page is different (meaning the content is posted already) and proceed to another web page.

Hope you could help me out with this. I'd really appreciate it. Thanks and more power!  :Thumb:

----------


## Zikrija

Hi Kleinma,
Very good job, but I have one questions.
In a web page I try to fill three combobox and then click on submit button. Web pages is .aspx, 
ComboBox in page
<label for="control28_ddDateOfPubMonth" id="control28_lbDateOfPubMonth" class="hide">Month</label><select name="control28$ddDateOfPubMonth" id="control28_ddDateOfPubMonth" class="date-month">
	<option selected="selected" value="-1" disabled="disabled">Month</option>
	<option value="1">January</option>
...

and button is
<a id="control28_btnSubmit" href="javascript**:__doPostBack('control28$btnSubmit','')">Search</a>

How can I fill this three combo box from forms  and then click onButton. This webPage do post back and I need render search result. 
I'm desperate. 
I try this 
DirectCast(GetCurrentWebForm.item("control28_btnSubmit", 0), mshtml.HTMLButtonElement).click()
but dosen't work. Never Click on button in this page.

I try WebZinc but dosen't work.

----------


## kleinma

From the HTML you posted, it looks like the submit mechanism on that page is an anchor (<A>) tag, and not an HTML Button. So casting it to an HTMLButtonElement is not going to do the trick.

Try casting it to a (I think the class name is) HTMLAnchorElement, and try calling click on that instead.

----------


## Zikrija

Tnx for you replay.
Do you mean 
DirectCast(GetCurrentWebForm.item("control28_btnSubmit", 0), mshtml.HTMLAnchorElement).click()

when I do this I get NullReferenceException.

Another thing when I use this WebZinc componente I have this error
Server Error in '/' Application.
Invalid postback or callback argument.  Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page.

Is it possible to make general automation on this web page???

----------


## xetic

Resolved my selecting of radio buttons with the following:



```
        
Dim theElementCollection2 As HtmlElementCollection = WebBrowser1.Document.GetElementsByTagName("Input")
        For Each curElement As HtmlElement In theElementCollection2
            Dim controlValue As String = curElement.GetAttribute("Value").ToString
            If controlValue = "VALUETOSELECTHERE" Then
                curElement.InvokeMember("click")
            End If
        Next
```

----------


## VisualBasic6

Thanks, I have solved my previous problem.

But now I have a different one.
Please open this URL http://support.euro.dell.com/support...dt1&l=en&s=bsd.
It will open Dell warranty search page. If service tag is blank kindly fill it with JNK630J. Now it will navigate you on a new page. On this newpage you will find a new link as Change Service Tag. If I click on the link it opens a new Dialogue and ask to enter new service tag no. I am not able to get the access of this dialogue box. I want to fill a new value in this box and want to click on Go.

How can I get access of this dialogue.
How can fill new no and click on Go.

----------


## beldoy

Hi all im new to this one...

I am trying to make an app in vb.net (part of visual studio 2005) that will do the following:

goto website login page and attempt login
if login fail goto website signup page and attempt signup
if login or signup success then
goto upload page and auto fill upload page and submit.

I would like to do this for say 10 sites.

I have tried 2-3 and managed ok but found that that doing more is very difficult.

Does anyone have any ideas as to how i can keep track within the code of say different upload page form items from the different sites.

Basically I want to make an auto submitter for my video to different video sites and the test for different site form elements and their names are making my code huge...

Just wondering if anyone knows an easier way.

Thanks

----------


## xetic

> Hi all im new to this one...
> 
> I am trying to make an app in vb.net (part of visual studio 2005) that will do the following:
> 
> goto website login page and attempt login
> if login fail goto website signup page and attempt signup
> if login or signup success then
> goto upload page and auto fill upload page and submit.
> 
> ...


If you want to do it on 10 sites, I would recommend you manually make sure you have accounts created at each one, then define credentials/path to upload form/form elements based on current url. That's my opinion based on the way I would code a site with a massive user base while trying to discourage bots. I wouldn't use standard form element names to make it easily automated, and even when not trying to make things difficult you will still most likely end up with 5 or more different form field name variations.

----------


## bl34ch127

Hello, I am trying to autofill a form that has no name or id. There are two forms on the page; the first is hidden while the second is the only visible form.

The visible form is a captcha and I have my COM webbrowser setup so that when it finds a captcha it asks for user input using inputbox()

I have tried countless different ways but I CANNOT find out how to fill the captcha form. Form some reason it refuses to fill.

Please help, oh and if needed I can supply my code and the html I am trying to use it on

----------


## gogeta126

hello. im using vb 2008 and trying to make a login program for sfront.ijji.com

currently i have this:

vb Code:
Public Class Form1        Private Sub CmdLogin_Click()        WebBrowser1.Navigate("http://sfront.ijji.com")        lblstatus.Text = "Connecting to IJJI Soldier Front...."    End Sub    Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, ByVal URL As Object)        If URL = "http://sfront.ijji.com" Then            WebBrowser1.Document.All("UserID").InnerHtml = user.Text            WebBrowser1.Document.All("Password").InnerHtml = pass.Text            WebBrowser1.Document.All("Sign In").Click()         End If       End Sub End Class

and the only error i get is this:
Error	1	'Public Event Click(sender As Object, e As System.Windows.Forms.HtmlElementEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.	C:\Users\Filip\AppData\Local\Temporary Projects\WindowsApplication1\Form1.vb	14	13	WindowsApplication1

please help

----------


## kleinma

I believe you need to use InvokeMember() to call click on a button like you are trying to do:

Something like:



```
webbrowser1.Document.All("Sign In").InvokeMember("click")
```

If that doesn't work try, "Click" or "click()", but I am pretty sure it is the one in the above code block.

----------


## kleinma

> Hello, I am trying to autofill a form that has no name or id. There are two forms on the page; the first is hidden while the second is the only visible form.
> 
> The visible form is a captcha and I have my COM webbrowser setup so that when it finds a captcha it asks for user input using inputbox()
> 
> I have tried countless different ways but I CANNOT find out how to fill the captcha form. Form some reason it refuses to fill.
> 
> Please help, oh and if needed I can supply my code and the html I am trying to use it on


I can't help you with bypassing a captcha.. The point of the code I provided is for automating websites that permit it. captcha is an obvious sign of a page that should NOT be automated.

----------


## dedeblank

hai.., how can i fill textbox inside frame? i had arround searching for this..,but still no result
thx before.

----------


## kleinma

you can try looking through the past pages of this thread. I am pretty sure frame access was discussed at some point.

----------


## bl34ch127

> I can't help you with bypassing a captcha.. The point of the code I provided is for automating websites that permit it. captcha is an obvious sign of a page that should NOT be automated.


The user will still be watched the page and inputting the captcha manually. I just want to fill the textbox!

----------


## Sjors

nvm ^^ :wave:

----------


## Sjors

Found out how to check the first radio button:



```
WebBrowser1.Document.GetElementsByTagName("Input").Item(0).SetAttribute("checked", "checked")
```

----------


## Sjors

anyone that can help me out saving the dynamic picture?

----------


## kleinma

I have nothing to say about captcha images. Period. Please do not ask for info here about bypassing, downloading, saving, or interpreting captcha images. They exist for a reason, and that reason is the sites they exist on DO NOT want to be automated, and want a human there doing the data entry.

----------


## abcat

is there a way to disable popup windows using your codes?

----------


## kleinma

if you are using the activex browser control (the one this article was written for), then you can handle the NewWindow3 event, which exposes the URL that is about to be popuped up, and exposes a cancel event arg you can set to true to cancel the popup.

If I remember correctly, the NewWindow3 event only fires on Windows XP SP2 and higher (which by no coincidence was when MS added the popup blocker to IE)

----------


## piklio

Hi dear kleinma
tnx for ur hlpful project !
but i have 2 question

first : 


```
DirectCast(GetCurrentWebForm.item(ID or Name), mshtml.HTMLInputElement).click()
```

in this  syntax we must use id on name of submt button . but sometimes for submit buttons there is no ID/Name . how can i click this button ?


second :
how u find the name or ID of button in web page ? i save the page and then browse page in frontpage or i read html codes and find name . is there any speedy way or any extension for browser that help us for finding button name faster than now ?

thanks in advance sir

----------


## kleinma

If an element has no id or name attribute, then the best you can do is grab all controls of a specific element type (like grabbing all input elements) and then looping them to see if one of the input elements has a type=submit attribute.

You can further verify with checking additional known attributes, like the value attribute which would have the submit buttons text.

As far as "how do you find elements names" and all that, if you use IE8, you can hit F12 when you are on a webpage, and it brings up a tool to go through the webpage DOM easily and find things like element names. There is even an option to allow you to simply click on the element you want on the page, and the utility tells you the info about it.

If you don't have IE8, you can get a similar tool via download (ie developer toolbar) for IE6 and IE7. I believe firefox also has similar tools, however I don't recommend using firefox when working with web automation, because some sites deliver different content (and have different behavior) based on browser version, and if you use firefox, you may find different results when using the IE based browser control in a windows app.

----------


## piklio

so great !
tnx
i solved my problem  and i can login  :Smilie: 

with this code :

with or loop i checked all value of items and then grab index of item that value equal to "log in" for example . 
then please ignore my last private message  :Smilie: 

for grabbing id and name in page tnx 2 . great idea . 
//
one orher small question :


```
Private Sub wb_NavigateComplete2(ByVal sender As Object, ByVal e As AxSHDocVw.DWebBrowserEvents2_NavigateComplete2Event) Handles wb.NavigateComplete2
        txt_page_source.Text = GetCurrentWebDoc.documentElement.outerHTML
    End Sub
```

 i use this code for grabbing page source
but when i call wb.navigate 1 time , then txt_page_source changed more times !
it means with one navigation , wb_NavigateComplete2 rase more times !
for wat ?
i need only last event and when everythings is complete !

tnx again sir

----------


## kleinma

naviatecomplete events fire when the initial navigation is done, not when the page has fully loaded into the browser. Use the DocumentCompleted event for that.

Either one of these events can fire multiple times if the page has frames or something similar where it is actually loading its content from different places.

----------


## piklio

> Either one of these events can fire multiple times if the page has frames or something similar where it is actually loading its content from different places.



tnx
but how can i know when page is loaded complete ?
 :Frown:

----------


## blazen2009

kleinma Thanks for the project! I'm a noob to VB.NET and Visual Studios 2008, but I have been interested in apps like this project and it will help speed up my learning.  :Smilie:

----------


## piklio

hi

how can make cockies dedicated from internet explorer ?

----------


## kleinma

I have no idea what that statement means.

----------


## piklio

> I have no idea what that statement means.


tnx mate
but it means i need login to gmail for example via m
and i dont want if anybody open IE and type Gmail.com can use my session on gmail  :Smilie:

----------


## kleinma

I still have no idea what you are asking for. I'm sorry. You really need to state your intent clearly and use full words.

"for example via m" doesn't mean anything to me...

----------


## piklio

> I still have no idea what you are asking for. I'm sorry. You really need to state your intent clearly and use full words.
> 
> "for example via m" doesn't mean anything to me...


 :Frown: 

"via m " in fact was :via my application" . it was my fault . sorry
i said ur application used IE coockies . and coockies in ur application and IE is same .
how can we segregate these coockies ?
and ur programms dont use IE coockies and IE dont use ur Program Cookies 

is it cleary ?

----------


## kleinma

is it cleary? well not really, but if you are asking about why *COOKIES* (not cockies, and not coockies) are the same in IE and the same in an app you make when using the webbrowser control, that is because they are one in the same. IE and the browser control use many common things, including settings. This is because the browser control is nothing but a part of IE that Microsoft exposes for you to use in your applications.

----------


## Skatebone

Hey kleinma,
First of all tnx alot for your project because it was very helpful  :Smilie: 
I managed to fill in textboxes but i have some problems regarding submit button.

First of all here is the site i am working with: 
https://weblogin.runescape.com/login...mentoptions.ws

1) I could not find Mshtml as a reference in the .net framework. (you need to download?)
2) Submit button didnt work for me
3) How can i do all this with web request and using a proxy?

Tnx alot  :Smilie:

----------


## stateofidleness

wow hope you're still reading this kleinma! this thread is priceless!

I have a DVR (digital video recorder) that I am able to log in to via browser to view the cameras. I have successfully logged in once using your provided code which takes me to a second page. 

I'm having a problem where, if I click the Submit button manually, it works fine. If I let my code do it (which worked the first time I ran the program), it gives me this "error": "Session ID removed from recorder & browser. " which is specific to the DVR, not IE.

Is it cookies or something that needs to be cleared before loading the page? I'm not sure why it worked the first time, then when I relaunched the program, it is basically telling me my login "timed out"

Thoughts?

----------


## Mailoo

Thanks for this thread, kleinma! It's been very helpful and it's great thing that you share your knowledge.

Now, to my topic. I need to retrieve anchor text from all links on some website, which contain specified string like "?seed=". The example HTML code:



```
 <div class="tablename">
                    <h2>blast</h2><table summary="Keywords"><thead><tr><th colspan="2" style="background-color: #505D71">3,886 searches (top 100 only)</th></tr><tr><th width="5&#37;">Searches</th><th class="keyword" width="94%">Keyword</th></tr></thead><tfoot><tr><td>3,886</td><td>total searches</td></tr></tfoot><tbody><tr><td>380</td><td><a href="?seed=scrabble+blast&amp;adult_filter=remove_offensive">scrabble blast</a></td></tr><tr><td>360</td><td><a href="?seed=blast&amp;adult_filter=remove_offensive">blast</a>
```

Now, as you see, links don't have any id's, so it needs to be done by searching the specified string within all links on the website, check if they contain string and then get only the text, like from :


```
<a href="?seed=scrabble+blast&amp;adult_filter=remove_offensive">scrabble blast</a>
```

I need to get only the words "scrabble blast" and do the same to all links on the website.

Now I have the code below, which doesn't work, I use standard WebBrowser from .NET 2.0. When I remove "TextBox2.Text &" from "TextBox2.Text & (element.OuterText) & vbCrLf" it gets text only from the last link on that website. When I run this one here, the app hangs my PC.



```
 Dim i As Integer

        For i = 0 To WebBrowser1.Document.Links.Count - 1


            For Each element As HtmlElement In WebBrowser1.Document.Links


                If element.GetAttribute("href").Contains("?seed=") Then
                    TextBox2.Text = TextBox2.Text & (element.OuterText) & vbCrLf


                End If

            Next
        Next
```

And also, I have a question - will it be working better if I use Regex? First, download the HTML source and then use Regex to retrieve what I want?

----------


## abcat

when i submit a unicode/ascii thingy eg. ★ string, it will display garbage character in the form response. The client program can display the program very well but not the server form. 

Do i need to do some conversion, i tried something like 
DirectCast(GetCurrentWebForm.item("varName"), mshtml.HTMLInputElement).value = System.Text.Encoding.ASCII.GetString(System.Text.Encoding.unicode.GetBytes("★"))  

but it came out other type of character instead.

----------


## VisualBasic6

How can we supress msgbox button on a webpage?
For example, there is a delete button on a webpage to delete something. However when you click this button it reconfirms before deleting the thing. It pops up a msgbox stating "Are you sure you want to delete the thing?" With Ok or Cancel button.
I do not want to disclose this button to the user and want to press ok button through my program coding. Or lets say when we click on logout on this website it display a msgbox to confirm it first. Is there any way to do supress this box and press ok through program?

----------


## kleinma

I had done some example code about supressing an alert box, you may be able to use it to do the same for a confirm box as well.

Another approach that SOMETIMES works (it all depends on the site) is to look at exactly what the button does when you click it. For example if the page is setup in such a way that when the button is clicked, it calls a JS routine to confirm with the messagebox, and as long as the JS routine returns true, it submits the form, then you could just directly submit the form via code. Again that all depends on how the specific page is setup and works.

Just note anything I do is in .NET, I notice your user name looks like you use VB6.

----------


## Mailoo

It's good to know that this thread is still alive  :Smilie:  

Is there any way to check if certain JS script has finished executing, sort of like "DocumentCompleted" event for page loading? Because DocumentCompleted doesn't work with javascript - there's no way to check if script has finished executing and the data are loaded. I'm using VB.NET 2005. Any help will be appreciated, thanks.

----------


## kleinma

There is nothing I am currently aware of that would allow you to know when javascript has finished executing, other than if there was something on the page you could keep polling and querying that could tell you.

----------


## Mailoo

Thanks for the reply. Too bad...right now I'm doing the way you suggested (checking for specific text on page), but it's not really reliable and elegant method. 

EDIT: Actually, I've just "discovered" WAY simpler method for checking if JS has finished. It's way better than actually looking through text with MSHTML TextRange (for my needs). InnerHtml method converts the current doc into plain html, thanks to that we can check if specific html element or text has already been loaded by Javascript. You can put the method in Timer or some loop. I'm pasting it here in case anyone needed it:



```
        If WebBrowser1.Document.Body.InnerHtml.Contains("html element name or text ") = True Then
            Timer1.Enabled = False

           ' code for saving elements from webpage - whatever you want to do with it :)



        End If
```

Sorry for a little chaotic post, but I'm really excited right now LOL  :Big Grin:  I've been fighting with this **** for like 2 days to solve it :P I guess I've tried to complicate things which are plain simple. And THANKS KLEINMA again for showing me the beautiful world of WebBrowser in VB.NET  :Big Grin:  LOL

----------


## abcat

is there a way to open a new instance or browser or change the default browser to firefox?

----------


## sonicsx

Hi, I have a little big trouble with C#, here it goes>
*************************htm code
      <FORM onsubmit=centerMap() action=javascript**:void(0) >
      <INPUT id=txtAddress > 

      <INPUT type=submit> 
      </FORM>
**************************************C# code to click on for submit..
webBrowser1.Document.Forms[0].InvokeMember("onsubmit");// it really works!!!

BUTT!!!!!!!! if I had this htm code in the same file.htm*********************
      <TABLE>
        <TBODY>
        <TR>
          <TD align=right>Latitud:</TD>
          <TD><INPUT class=inputField id=txtLatitude></TD></TR>
        <TR>
          <TD align=right>Longitud:</TD>
          <TD><INPUT class=inputField id=txtLongitude></TD></TR>  
	<TR>
          <TD align=right>Nivel m&#237;nimo de acercamiento:</TD>
   	  <TD>
	<INPUT id=txtLevel size=3 value=3> <INPUT onclick=addPoint() type=button>
	</TD>
	</TR>
	<TR>
          <TD align=right colSpan=2></TD>
        </TR>
        </TBODY>
      </TABLE>
*****************************I can't simulate the click event, I tried with...
webBrowser1.Document.Forms[0].InvokeMember("onclick");//fail!! I think the problem is there is no form on this part of the code, so I can't perform that...what I know that works is "webBrowser1.Document.*???????????*.InvokeMember("onclick");" I made some test and this is what I got. Somebody I need some help!!!!!!

----------


## kleinma

It looks to me like addPoint() is just a javascript function defined somewhere else in the HTML. Why not just make a direct call to addPoint() ? My example code download shows how to execute javascript directly.

----------


## Mailoo

@sonicsx: Check this out...maybe it'll work in your case too...I use it javascript based form


vb Code:
For Each element2 As HtmlElement In wb.Document.GetElementsByTagName("input")            If element2.GetAttribute("onclick") = "addPoint()" Then element2.InvokeMember("click")         Next

----------


## tjcj

kleinma I a noob to vb.net and visual studio, I have a couple of questions I hope you can answer.

Can your code for filling a textarea be used for the regular webbrowser?
Also how do we add the browser from your project to a new project?

Also in a new project I created when I use "mshtml.HTMLTextAreaElement" in your code, visual studios say it is not defined, but this not a problem when I load your project. What could be the reason for this?

----------


## kleinma

1) regular webbrowser? what is a "regular" webbrowser (other than one that is not google chrome  :Wink: ) Do you mean the standalone IE browser, and not the webbrowser control that you would put on your own form? The answer is no, you can't. You can, but it requires you to write a plugin to IE, not just write code in a VB.NET app that uses a browser control.

2) Right click on your toolbox and select "choose items", the go get coffee while that dialog box loads, and the click the COM Components tab, and find "Microsoft Web Browser" and check it off. This should add the COM browser to your toolbox. Note it does not replace the managed .NET browser.

3) do you have a reference to mshtml set? Do you even have mshtml.dll on your computer? You may need to search for it. I am pretty certain somewhere above in the last 430 posts there is a link to download it if needed  :Wink:

----------


## tjcj

Thank you for responding kleinma.  :Smilie: 

So then would this work on the webbroswer control that go on the form?
As for mshtml.dll I have the file, but I didn't have a reference set to mshtml.




> 1) regular webbrowser? what is a "regular" webbrowser (other than one that is not google chrome ) Do you mean the standalone IE browser, and not the webbrowser control that you would put on your own form? The answer is no, you can't. You can, but it requires you to write a plugin to IE, not just write code in a VB.NET app that uses a browser control.
> 
> 2) Right click on your toolbox and select "choose items", the go get coffee while that dialog box loads, and the click the COM Components tab, and find "Microsoft Web Browser" and check it off. This should add the COM browser to your toolbox. Note it does not replace the managed .NET browser.
> 
> 3) do you have a reference to mshtml set? Do you even have mshtml.dll on your computer? You may need to search for it. I am pretty certain somewhere above in the last 430 posts there is a link to download it if needed

----------


## Shane Lowe

*kleinma --*

Are there any ways to perform browser manipulation on Compact Framework 3.5?  I'm looking to auto-login to a website on a Mobile 6 phone. Your .net demo app was great and is exactly what I was looking for a example but I'm working with the compact framework..Any help would be GREATLY Appreciated. I have the skeleton of my app built but can't get pass this problem.

Thanks!

----------


## sunnydsouza

First of all,let me THANK you for providing WebpageManupilation code.I am a beginner in VB.net and I found the mshtml method extremely easy and understandable.

I am creating an autosurfing application(where the application automatically surfs webpages and fills in information) to make my work simple.
Now my application using your WebpageManupilation methods which works perfectly on phpBB boards.

However on vBullettin boards it is giving me some problems

Here is my code for entering some info in a form for submitting new thread


VB.NET Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click         DirectCast(GetCurrentWebForm.item("subject"), mshtml.HTMLInputElement).value = "Sunny"    'this TOTALLY DOESNT WORK GIVES ERROR        wb.Document.All("subject").setAttribute("value", "sdsdsdsdsd")           ' this WORKS!!!        wb.Document.All("message").setAttribute("value", "sdsdsdsdsd")           ' this DOESNT WORK but no ERROR            TextBox1.Text = wb.Document.All("preview").getAttribute("name")        'DirectCast(GetCurrentWebForm.item("message"), mshtml.HTMLTextAreaElement).value = "Sunny"        'DirectCast(GetCurrentWebForm.item("cmdSubmitMe", 0), mshtml.HTMLButtonElement).click()        'GetCurrentWebForm.submit()    End Sub

The error I get is *"Object reference not set to an instance of an object."*

the code

vb.net Code:
wb.Document.All("subject").setAttribute("value", "sdsdsdsdsd")           ' this WORKS!!!        wb.Document.All("message").setAttribute("value", "sdsdsdsdsd")

somewhat works but still the "message " field in the form doent fill up

The source code of  of that form is exactly the same as the one use use to create a new topic in this forum(since its a vBullettin board) except the textarea field is hidden and there is an addtional iframe under it(dunno what it does???)


Subject field


```
<input class="bginput" type="text" tabindex="1" maxlength="90" size="40" value="" name="subject"/>
```

MEssage Field


```
<table width="100&#37;" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr valign="top">
<td class="controlbar">
<textarea id="vB_Editor_001_textarea" dir="ltr" tabindex="1" style="display: none; width: 540px; height: 250px;" cols="60" rows="10" name="message"/>
<iframe id="vB_Editor_001_iframe" tabindex="1" style="border: 2px inset ; width: 540px; height: 250px;">
<html>
<head>
<style type="text/css">
1.wysiwyg { background: rgb(244, 244, 244) none repeat scroll 0% 0% !important; -moz-background-clip: border !important; -moz-background-origin: padding !important; -moz-background-inline-policy: continuous !important; color: rgb(0, 0, 0) !important; font-family: verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif !important; font-style: normal !important; font-variant: normal !important; font-weight: normal !important; font-size: 10pt !important; line-height: normal !important; font-size-adjust: none !important; font-stretch: normal !important; -x-system-font: none !important; }
2 p { margin: 0px; } .inlineimg { vertical-align: middle; }
</style>
</head>
<body class="wysiwyg" spellcheck="true" linkifying="true" linkifycurrent="0" linkifymax="0">
<br/>
</body>
</html>
</iframe>
</td>
```

Somewhat I am having problems clicking "Submit post" and "Preview" buttons.
I dont understand why mshtml doesnt work??
Am I doing something wrong?? PLEASE HELP!!!

----------


## kleinma

sounds like a bot, so I hope you don't plan to use this on vbforums vbulletin to make posts...  :Wink: 

GetCurrentWebForm if I remember correctly is sort of assuming that there is only 1 form on the page. If the page has more than 1 form, then you need to make sure you are grabbing the correct form that actually contains those fields you wish to fill in. wb.document.all() is going to search the entire DOM for the given field. So check that first and post back.

As far as the textarea issue, textareas have an innertext property to set I believe versus a value attribute.

Standard HTML is different for textareas..

<textarea>this is the text in the textarea box</textarea>
<input value="this is text in a textbox">

see the difference?

Let me know how you make out.

----------


## sunnydsouza

Yeah Thanks for replying....I checked out and indeed there were some hidden forms on the page so I had to change the index value to 3. Now things are working out smoothly except that the TEXTAREA problem still exists.

i tried innertext,innerHTML etc but nothing seems to work.The textarea simply doesnt fill in
I am really getting frustrated with this problem.Please could u have a look on my previous post #434 and see if u could find a solution

I guess the problem is the textarea field is hidden...Does that affect the program??

<td>
 <textarea>      '''' Its HIDDEN
 </textarea>
   <iframe>
     <html>

      </html>
   </iframe>

</td>

GOD Knows whose value to set to get the message field filled up correctly.Thats the last of my problems bugging me now  :Frown: 


P.S EDIT: Maybe I got the Problem but no solution till now.Maybe this will make things easier for u to find a solution

I found that the hidden textarea field value is only changed after submitting the post.However what really changes when I type my post,is the the value within the body tag which is inside the IFRAME.Maybe I need to set the Ifram's innertext but for some reason am not able to get to the iframe since it doesnt have a name only Id.I tried putting the ID but not Working...throws an exception

Here is an image I took with firebug working in action


Hope this makes it clear of my problem  :Cry:

----------


## EWiggins

:Big Grin: Senerio: I am selecting values on the web page and clicking submit button via code and it returns a Excel sheet. I would like to be able via code get that file and place it in a designated folder.

            For Each cdHTMLS In GetCurrentWebDoc.getElementsByTagName("input")
                If cdHTMLS.type = "radio" And cdHTMLS.name = "ogrp" And cdHTMLS.value = "GW" Then
                    cdHTMLS.click()
                    Exit For
                End If
            Next

            For Each cdHTMLS In GetCurrentWebDoc.getElementsByTagName("input")
                If cdHTMLS.type = "radio" And cdHTMLS.name = "output" And cdHTMLS.value = "xls" Then
                    cdHTMLS.click()
                    Exit For
                End If
            Next

            For Each cdHTMLS In GetCurrentWebDoc.getElementsByTagName("input")
                If cdHTMLS.type = "submit" And cdHTMLS.value = "Submit" Then
                    cdHTMLS.click()
                    Exit For
                End If
            Next

----------


## Abantu

I am reading text from a webpage using the webrowser control. How do i read the value of the text in the "class" snippet below:

<div id="baseDiv" class="date-20090918 expired-info  ">


I want my app to just get 20090918

My code snippet below does not seem to return the value



```
Dim theElementCollection As HtmlElementCollection = AxWebBrowser1.Document.GetElementsByTagName("div")
        Dim controlName As String
        For Each curElement As HtmlElement In theElementCollection

            controlName = curElement.GetAttribute("id").ToString

            If controlName = "baseDiv" Then
                'this brings empty msg box
                MsgBox(curElement.GetAttribute("class").ToString())
                Return True
                Exit Function
            End If
        Next
```

Any help is appreciated

----------


## kleinma

Use "classname" as the string instead of just "class". I know it doesn't make a ton of sense when the actual HTML just has a class attribute, but it works.  :Wink:

----------


## psmith65

sunnydsouza,

I have bee struggling with the same problem with the textarea's in the iframe.  I only just worked it out today after countless frustrations on it.  Here is the soltuion that seems to work:



```

WebBrowser1.Document.Window.Frames("vB_Editor_001_iframe").Document.Body.InnerHtml = "abc"
```

Allelulia !!!!  I can't believe how hard this was to work out.

----------


## kleinma

psmith, that fills a textarea in an iframe, or just replaces the entire contents of the iframe with "abc" ??

----------


## psmith65

kleinma,

For the latest vbulliten boards this will fill in the textarea.  The reason being that they use javascript to copy the entire contents of the iframe into the textarea on the submit.

So to fill in the textarea for a Vbulliten board (only latest couple of versions) you can use the code I posted.

For most other textareas you can just find the textarea and set the value as per usual.

Hope that exlpains it a bit better.

----------


## kleinma

Yeah that makes more sense.

----------


## blazen2009

Mistake

----------


## 9277463

> Because your have elements all named the same thing (vehicle and sex) there is no way to simply grab one like you are doing and set a value. Trying to grab just one will just give you the first matching element. You need to grab them all, and loop them until you are on the element you want, then take action on it.
> 
> Radio buttons and Checkboxes often have the same name or id properties, so this is approach needed often when dealing with these.
> 
> First I use this subroutine to check/uncheck a radio or checkbox.
> 
> 
> 
> ```
> ...




I try the trick of the checkbox but it did not work with me if you can upload us an example to understand the idea please

----------


## Jdro04

I have run into a problem.
I used your sample code to build a program that logs into a site.  Navigates to a page I want, but now I am stuck.

There 4 groups of radio buttons and after checking the first set, depending on which one you clicked, some of the second set of radio buttons opens up.

I successfully managed to check the first radio button, but the second group doesn't open up.

Is there a way to send an actual click to it?

I have tried both of these methods.

vb Code:
DirectCast(wb.Document.all.item("fp1-1", 0), mshtml.HTMLOptionButtonElement).checked = True
DirectCast(wb.Document.all.item("fp1-1", 0), mshtml.HTMLOptionButtonElement).click()

Neither works.

I think it may have something to do with sending a javascript execution.

Here is the page source Im working with if that helps.  Just the portion I think might be relevant.


```
<div class="nav_space" id="nav_space"></div>
		<div id="view_all_cats_spacer" style="display: none;"></div>
<script src="https://images.associatedcontent.com/services/2.0.0/js/ac_ajax_win_takeover.js?v=68" type="text/javascript"></script>
<script src="https://images.associatedcontent.com/services/2.0.0/js/ac_call.js" type="text/javascript"></script>
<script LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/include/classes/thirdparty/jspellEvolution/jspellEvolution.js" CHARSET="ISO-8859-1"></script>
<script LANGUAGE="JavaScript" TYPE="text/javascript" SRC="/include/classes/thirdparty/jspellEvolution/jspellSettings.js" CHARSET="ISO-8859-1"></script>

<div id="read_call" class="input_panel" style="display: none;"></div>
<div id="page_screen" style="display:none; ">&nbsp;</div>
<script language="javascript" type="text/javascript">
	var goto ='/cms_edit_article.shtml';
	var oAjaxWinTakeOver = new AjaxWinTakeOver("page_screen");
	var oSearchResultPanel = new  SearchResultPanel("read_call");
	var oSearchResultRetriever = new SearchResultRetriever( "actions_call.shtml", 'call_detail_for_cp' , [oSearchResultPanel] );


	String.prototype.trim = function() {
	str = this.replace(/^\s+/, '');
	return str.replace(/\s+$/, '');
	};


	function show( date ) {
		if ( date == 'release_date' ) {
			document.forms['articles'].release_date.value = '10/09/2009 09:19:03';
		}else if ( date == 'expire_date' ) {
			document.forms['articles'].expire_date.value = '10/09/2009 09:19:03';
		}
	}
	function isCallRetain() {
		var isChecked = 0;
		   }

	function checkValue( form ) {
		var elem = document.forms['articles'].elements;

		var exclusiveExists = 0;
		var distibutionExists = 0;
		var paymentExists = 0;
		var isExclusiveChecked = 0;
		var isDistributionChecked = 0;
		var isPaymentChecked = 0;
		var isFilePresent = 0;
		var isVideoGamePlatformChecked = 0;
		var isVideoGraphicsAudioChecked = 0;
		var isVideoGamePlaySelected = 0;
		var isVideoCreativitySelected = 0;
		var isVideoFunSelected = 0;
		var isCountryUSA = 0;
		var isState = 0;

		
		if ($('prev_pub1') && $('prev_pub2')){ // exclusive
			if ($('prev_pub1').checked == false && $('prev_pub2').checked == false){
				alert('Please indicate whether you have previously published this content.');
				return false;
			}
		}

		if ($('fp1-1')){ // exclusive
			exclusiveExists = 1;
			if ($('fp1-1').checked == true){
				isExclusiveChecked = 1;
			}
		}

		if ($('fp1-0')){ // non-exclusive
			exclusiveExists = 1;
			if ($('fp1-0').checked == true){
				isExclusiveChecked = 1;
			}
		}

		if ($('fp1-2')){ // display only
			exclusiveExists = 1;
			if ($('fp1-2').checked == true){
				isExclusiveChecked = 1;
			}
		}

		if ($('syndication1')){ // distribution yes
			distributionExists = 1;
			if ($('syndication1').checked == true){
				isDistributionChecked = 1;
			}
		} else {
			isDistributionChecked = 1;
		}

		if ($('syndication2')){ // distribution no
			distributionExists = 1;
			if ($('syndication2').checked == true){
				isDistributionChecked = 1;
			}
		} else {
			isDistributionChecked = 1;
		}

		if ($('fp2-1')){ // upfront
			paymentExists = 1;
			if ($('fp2-1').checked == true){
				isPaymentChecked = 1;
			}
		}

		if ($('fp2-0')){ // perf
			paymentExists = 1;
			if ($('fp2-0').checked == true){
				isPaymentChecked = 1;
			}
		}

		if ($('fp2-00')){ // minor no pay
			paymentExists = 1;
			if ($('fp2-00').checked == true){
				isPaymentChecked = 1;
			}
		}

		if (isExclusiveChecked == 0 && exclusiveExists == 1){
			alert('Please select which type of rights you would like to grant for this content.');
			return false;
		}

				if (isDistributionChecked == 0 && distributionExists == 1){
			alert('Please choose whether to make this content eligible for distribution with approved AC partners.');
			return false;
		}
		
		if (isPaymentChecked == 0 && paymentExists == 1){
			alert('Please select which type of payment you would like for this content.');
			return false;
		}

		
		
		if ($('mast')){ // master license
			if ($('mast').type != 'hidden'){
				if ($('mast').checked == false){
					alert('To continue, you must read and agree to the terms and conditions of the Master License Agreement by checking the box.');
					return false;
				}
			}
		}

		if ($('wfh')){ // work for hire

			if ($('wfh').checked == false){
				alert('To continue, you must read and agree to the terms and conditions of the Work for Hire Agreement by checking the box.');
				return false;
			}
		}
```

If they were all unlocked from the beginning I wouldn't have problems, but they are not.

----------


## Allex19

Hi 

I try to fill textarea on this page http://www.exbii.com/newthread.php?do=newthread&f=50

This code doesn’t work in my program



```
WebBrowser1.Document.Window.Frames("vB_Editor_001_iframe").Document.Body.InnerHtml = "abc"

or

WebBrowser1.Document.Window.Frames(2).Document.Body.InnerHtml = "abc"
```


I use VB 6.0 and WebBrowser. Can you help me and give corrected code

----------


## psmith65

Allex19,

Do you get an error ?  or it just doesn't populate ?

----------


## Allex19

Yes I get error

“Object doesn’t support this property or method”

----------


## psmith65

Allex19,

What version are you using.  The code posted has been tested on VB 2008 Express Edition. When I open your project it tells me I need to upgrade it so I assume your on an earlier version.  I don't know the equivalent commands on the earlier versions.

----------


## Allex19

I use the old version of Visual Basic 6.0

----------


## psmith65

The smae premise should apply.  You just need to work out the code.  This is what you need to do:

Get the document object (DOM) from the webbrowser.
Find the frames in the DOM.
Find the frame called vB_Editor_001_iframe
Get the document from the frame
Set the body innerHtml to the value you want to put in the text area.

Thats pretty much it but I don't know the associated commands in the old vb 6.

----------


## Allex19

Psmith65 thanks for your help. I decided to write a program in VB 2008

----------


## cafc2

Hello, Can somebody explain who can i select all web document, in order to copy the html content? 

I saw in WebpageManipulation code that is possible to find text in web page. but i want select all the web page.? 
thanks in advance,
cafc

----------


## kleinma

You just want to get all the HTML from a give page?

----------


## cafc2

yes!!!

----------


## cafc2

but i am not interested in html code... because its doesn't show the information that i what!

----------


## kleinma

You need to explain a bit more then. You state you want all the HTML from a given page, and then you say you are not interested in the HTML code. It can't be both.

----------


## cafc2

ok! i want get the data from a web page and not the html! there a lot of samples on internet to get/parser html! but none of them works in my case because the page that i want get data is a bit more complex... so i want use a object like webrowser or other and then select all the content of page in order to extract the data? 

this is your code... what I want is to select all text on web page to get the data, instead of finding a specific string, do you understand what i mean?

 Dim MyRange As mshtml.IHTMLTxtRange = Nothing
        MyRange = DirectCast(mydoc.selection().createRange, mshtml.IHTMLTxtRange)
        If MyRange.findText(Text) Then
            MyRange.select()
            Return True
        Else
            Return False
        End If

thank you very much

----------


## kleinma

If you just want to grab ALL the text from a webpage, then I would just consider grabbing the value of 

_WebbrowserInstanceName_.Document.Body.InnerText

This is different from InnerHTML which will actually contain HTML markup code. The InnerText property ONLY returns text rendered in the HTML, the stuff visible on the screen.

----------


## cafc2

thanks for yours answers! 
If i have this code for instance:

webBrowser1.Navigate("http://www.yahoo.com");
string q = webBrowser1.Document.Body.InnerText;

the variable q will not contain all text present on yahoo webpage! for that reason i said that I wanted find a solution that select all the webpage to be possible to copy all text in the webpage!!
thanks again

----------


## psmith65

cafc2,

You need to give it time to navigate to the webbrowser.  You are hitting the web page while it is still loading (or not even started to load).  It will be empty till the page has loaded.  Do a quick search on waiting for the webbrowser to load and you will find some code to handle it.

----------


## cafc2

Hi!
Yes of course!!! in above code i forget to say that de second line of code is executed only when webpage on webbrowser is completed, ok? for that reason i said that the variable q "will not contain *all* content" it means that after the webpage is complete downloaded i get only a part of text of the yahoo webpage! i know this is situation a little bit complex.... thanks

----------


## cafc2

i try this.... and also doesn't work at all....

WebBrowser1.Document.ExecCommand("SelectAll", False, Nothing)
WebBrowser1.Document.ExecCommand("Copy", False, Nothing)


neither this solution works on my webpage:

some webpage works.... for instance.... yahoo.com works well but not in my webpage.... 

 CDO.MessageClass message = new CDO.MessageClass();

            message.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");

            ADODB.Stream stream = message.GetStream();

            stream.SaveToFile("c:\\test.mht", ADODB.SaveOptionsEnum.adSaveCreateOverWrite);

----------


## kleinma

> Hi!
> Yes of course!!! in above code i forget to say that de second line of code is executed only when webpage on webbrowser is completed, ok? for that reason i said that the variable q "will not contain *all* content" it means that after the webpage is complete downloaded i get only a part of text of the yahoo webpage! i know this is situation a little bit complex.... thanks


It looks to work fine for me.. maybe you aren't really using Yahoo and only used that as an example. Is the page you are trying to get all the text from a single frame page, or does it have multiple frames? Maybe it has IFrames on the page? If it is more than 1 frame, you would have to grab each one individually.

----------


## cafc2

yeah.... probably is that..
thank very much for yours quick answers....

----------


## tamalero

Hello there, I'm having a small problem.

I'm trying a program that will go to this website: 
http://weather.msfc.nasa.gov/GOES/goeseastconus.html

then it will input the cordinates in the lower box.
then once the page as been sucesfully loaded, I want to extract the url of the big Image to be hable to download it. ( its a school proyect )

I tried using your COM webbrowser component, and it worked perfectly until the page after you send the cordinates loads to ejecute the next code..
problem?
every comparation I try to make a "wait time" until the next page is load, seems to be ignored by the program, it doesnt fully load, so it always detects only the icons and not the full image.

(example, the page mentioned above, after entering the cordinates and applied the form, goes to this page http://weather.msfc.nasa.gov/cgi-bin/post-goes, this page will display a "close up" of the cordinates, and also a few icons, including the NOAA. )
your program-code does detect the icons just fine. but not the main Image.

I tried using :


```
   While AxWebBrowser1.ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_LOADING
            Application.DoEvents()
        End While
```

and the code seems to work, but its ignored. (I want to pause the program until everything as sucesfully load, this needs to be done by the component and not by timers, as the place where the program will be deployed as very lousy internet connection ).

then by switching to the normal VS2008 web browser component.
I cant seem to be hable to use your conversion to mshtml.htmlformerelement

the code of your program :


```
 Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
        Try
            Return DirectCast(wb.Document, mshtml.HTMLDocument)
        Catch ex As Exception
            Return Nothing
        End Try
    End Function
```

raises a warning of "Runtime might occur when converting system.windows.form.htmldocument to mshtml.htmldocument"
WB.document = document of the VS2008 Web browser component

also is there a way to do it all silently and not in the visible way?
Ie, be hable to "input" the cordinates silently and get the resulting html ( I've done html parsing to get the http address of the images, so thats not  problem  )

*addenum*
I tried using the way other people recommended here
using wb.isbusy = true along with the wb.readystate = 4.
and still doesnt work, somehow it skips it and trows instantly an instance error on the directcast part where I want to "select" a textbox in a form. (the page clearly hasnt fully loaded)
I also tried a few variants and still.
any suggestions?

Also is there a way to do this but "hidden" similar to what MC_F was suggesting?
the problem is, if use the "webbrowser (com one) document completed it works, but and enters the form data and submits, but its still not automated, I have to click anywhere in the com component to somehow "activate" it.
wich is weird, as I have it focused.
sorry for all the question, I'm in no way an expert in programming and I get confused quite easily.

----------


## DragonBoy

I downloaded you WebPageManupulation zip file from your first post and ran it.But it gives an error when i open it saying :
"The selected file is not a valid Visual studio solution file".
i am using VS 2006.

ANyways,i use the following coding to get the element and manupulate it usually:



```
For Each ele In WebBrowser1.Document.getElementsByTagName("input")
   If ele.Value = "Tag Name" Then ele.Click:
   Next
```

But i don't know how can i disable certain images that i see on a webpage using this coding.
Any suggestion how i can disable certain images(not all) using this coding perhaps.

----------


## kleinma

There is no such thing as VS2006

What do you mean by disable images? You mean just not show them?

----------


## coldfire417

I'm having trouble.  I wan't to search a website for a certain MD5 hash checksum. The site is  http://virustotal.com/buscaHash.html
If it finds results, how could I list them within a listbox?

----------


## DragonBoy

I meant Visual Studio v.6.

And,yes.
You see the problem is that i usually go to this site with many images.Now i don't need all those images except for one which is present in a certain web page which is the reason i can't disable all images on my browser since i need to keep the image activated on one single webpage on that site but don't need other images on that website.
The images take alot of my internet speed you see.

----------


## dr_aybyd

@klienma

Thanks for this tutorial..I figured it how to auto fill textbox in form and solve my problem..
I got a question for you.
Is it possible to collect data in this page with table. link here 

Is t possible to collect and view the data from tables into a ListView control in winForm?
Instead of viewing page in webbrowser. i just want to use listview.

Thanks for the help..

----------


## iceqb

kleinma!!! 
4 years and you are still helping! You are amazing. Just finished reading 13 pages and what an amazing person you are! Wow! Never come across a guru like you!

Joined this forum to ask for help!

I have a web browser control through which I am able to pass the user name and password and invoke a submit event. The problem now is that as soon as a login happens,  a PDF file is downloaded and this appears in a File Download dialog box. The point is that I am trying to build a windows application which is automated. So there is no room for popups or dialog boxes. What I actually need to do is to capture this pdf download onto the local disk without the File Dialog intervention.

I have struggled with this for a month. No luck! I pray to god that u read this post and help me!

Thanks for all the great work you are doing!

Cheers,
iceqb

----------


## kleinma

ahh my friend flattery will get you no where with me  :Wink: 

When you log into the page, is the page that you end up at actually a PDF document? Or do you end up at a normal webpage which spawns a PDF in a popup window? One thing I find odd is that you are getting a file download dialog for a PDF document. That usually only happens when you don't have a PDF reader installed. When I navigate to a PDF either in IE or the browser control, it simply opens up either in the browser directly, or in adobe reader/acrobat.

So what is the exact behavior going on ?

----------


## iceqb

Thanks for the quick response. Yes, like you guessed, I do not have pdf reader installed on a server machine. And as u said again, post authentication, I end up with a pdf file. So is it possible to capture this download into a file within a browser control. (There will be no instances of PDF reader on the machine)!

Please help!

Thank you a million!

Cheers,
IceQB

----------


## iceqb

BTW, missed out to mention. I really meant what I said. and wasn't intended to turn out as flattery. :-P

Thanks once again!

Cheers,
IceQB

----------


## kleinma

Well, I don't know the ins and outs of how your exact web app works that you are trying to do this for. If it works how I assume it does, you may be able to do something like this:

in the navigating event of the browser, you can cancel navigation. So IF in fact this event fires when the PDF doc is navigated to, you could grab the URL, and then cancel navigation, and download the file manually since you would have the URL to it. Depending on if authentication would block this or not, I guess that it something you would have to test.

Something along these lines:

note it assumes the URL of the PDF actually ends with pdf (there is no extra data after in the URL)


```
    Private Sub WebBrowser1_Navigating(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserNavigatingEventArgs) Handles WebBrowser1.Navigating

        If e.Url.ToString.EndsWith("pdf") Then
            Dim myFileURL As String = e.Url.ToString
            My.Computer.Network.DownloadFile(e.Url.ToString, "C:\myfile.pdf")
            e.Cancel = True
        End If

    End Sub
```

----------


## iceqb

Awesom. Thanks a lot pal. Will try an post. Thanks once again!  :Smilie: 

Cheers,
IceQB

----------


## luke18

Hi! kleinma pls help me i try to make an autosubmit program for this website:www.facebook.com
 for the reg form.but i try many way for clicking the submit(Sign Up) button but i cant do it...could u help me??
I try .InvokeMember("submit")
System.Windows.Forms.SendKeys.Send("ENTER")
but it doesnt work:S
I use vb 2008, pls help me:/
many thanks!!

----------


## JK-CodeBuster

Hi kleinma,

i am able to login to a web page based on your above code....now i wanted to test all the username along with its pwd which is default 123456

user name from database will be check for pwd 123456  how can i get to know which all users has changed its pwd


i am able to login with correct username and password

i used WebBrowser1_NewWindow event because if user name is correct the url gets changed but how can i get to know that a particular users has changed its pwd

When Pwd is entered wrong there is no change in the url or no window is changed only the page display a warning message saying Login Failed ! Invalid Username or Password

Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

If WebBrowser1.Url.AbsoluteUri = "http://192.168.10.4/cgi/index.php?dispSession=1" Then
            MsgBox("Correct Pwd")

End If
End Sub

----------


## JK-CodeBuster

Hi kleinma,

i am able to login to a web page....now i wanted to test all the username along with its pwd which is default 123456

user name from database will be check for pwd 123456  how can i get to know which all users has changed its pwd


i am able to login with correct username and password

i used WebBrowser1_NewWindow event because if user name is correct the url gets changed but how can i get to know that a particular users has changed its pwd

When Pwd is entered wrong there is no change in the url or no window is changed only the page display a warning message saying Login Failed ! Invalid Username or Password

Private Sub WebBrowser1_NewWindow(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles WebBrowser1.NewWindow

If WebBrowser1.Url.AbsoluteUri = "http://192.168.10.4/cgi/index.php?dispSession=1" Then
            MsgBox("Correct Pwd")

End If
End Sub

----------


## CAVU

I'm using VB6 and using the webbrowser control to fill the form and submit to a commercial website that has weather.  The problem is I can determine that the initial website has completely loaded by using the DocumentCompleted method.  I then can fill the form with the city that I want and submit. The DocumentCompleted subroutine is not triggered again.  THe only way I could figure out how to wait for the response from the server was to count the number of TitleChange events that occurred.  THen I can parse the page for the info I need.

Is there a more elegant way to do this in VB6?

----------


## abcat

Is it possible to use VB Control (textbox & button) instead of loading external html to submit a form?

----------


## CAVU

Loading the website is simple and small code foot print.  The webbrowser can be hidden so the user doesn't see anything.  I'm thinking the ReadyState property holds the answer to my problem (though I see someone else is using the Title count also, wonder why)

Bypassing the webbrowser would require significant coding (cookies etc)

----------


## luke18

Pls guys help mee i saw that u have a lot of work in this forum.
It iis so helpful. but i cant solved this problame.
I wanna fill a form and submit it ,i can fill it but the submit methode doesnt work :Frown: 




Code:
<input type="hidden" id="referrer" name="referrer" value="116" autocomplete="off" /><input type="hidden" id="challenge" name="challenge" value="f6c75d9cda8d09a31ccc9a59d3e1ab7a" autocomplete="off" /><input type="hidden" id="md5pass" name="md5pass" value="" autocomplete="off" /><div class="reg_btn clearfix"><span class="UIButton UIButton_Green UIFormButton"><input value="Sign Up" type="submit" class="UIButton_Text" onclick="return run_with(this, [&quot;reg-util&quot;], function() {RegUtil.getInstance().ajax_validate_data({ignore: ['captcha']}, &quot;registration_container&quot;, &quot;1&quot :Wink: ;});" /></span>

pls help me:$
I use VB 2008

and i tired 
.InvokeMember("submit")
System.Windows.Forms.SendKeys.Send("ENTER")
but doesnt work.
many thanks







> Hi! kleinma pls help me i try to make an autosubmit program for this website:www.facebook.com
>  for the reg form.but i try many way for clicking the submit(Sign Up) button but i cant do it...could u help me??
> I try .InvokeMember("submit")
> System.Windows.Forms.SendKeys.Send("ENTER")
> but it doesnt work:S
> I use vb 2008, pls help me:/
> many thanks!!

----------


## Emperor92

Very intresting article, what about filling in Java textareas?

----------


## willstaa

Hi ive used this thread to help me alot, when trying to get data from a web site for a internal system. ive now come across a problem which im a bit stuck on.

the site im working with isnt  mine but a site we pay to use for data, on most of the pages i have mangaed to get the data or set or update fields but im having issues when trying to set the value on this box

SELECT class=userPerpage onchange=changeRecordsPerPage() name=pageSize><OPTION 
  value=10>10</OPTION> <OPTION value=25 selected>25</OPTION> <OPTION 
  value=50>50</OPTION> <OPTION value=100>100</OPTION></SELECT>

abi is the name of my web window

ABI.Document.All.Item("pageSize").InnerText = 50 

also tried the innertext is quotes, i have also tried the following

ABI.Document.All.Item("pagesize").InvokeMember("click")

any ideas, many thanks

----------


## willstaa

well i solved that problem, by doing this 

ABI.Document.All("pagesize").SetAttribute("value", "50")

simple once i found it out

i now have another issue, the form has two buttons called go, crap i know.

this is the one i want to run
 <INPUT class=button id=Save style="WIDTH: 30px" onClick="return validate('GO');" type=submit value=Go name=Go>

this is the one i dont want to run
<INPUT class=button id=searchButton onClick="return getQuickSearchProjectDetail();" type=button value=Go name=Go> 

can you refer to the id as i see one is called searchbutton and the other is called save, i had tried just running the javacode but that didnt work

thanks im running vb2008

----------


## Rally

Hi, 
Please forgive my Ignorance here but I'm going to ask anyway!
I still don't see how this is going to log into a website that requires a username and password.  I am trying to follow along with this thread but am still stuck.
I have made an App. to just store links User names and passwords to all the sites I go to (just like this one) and I thought it would be nice if I could login automatically.  I would really appreciate some help.

----------


## CAVU

I have worked with this quite a bit.  Its tricky

Basically I use 


vb Code:
PA="the URL"
WebBrowser1.navigate (PA)
Then in 


vb Code:
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
 If URL = FP & "/" Then  'notice that you may have to check if the end back slash is there, it isn't always.  Also, this procedure is fired a couple of times and you need to check to see what page is being completed.
 Do Until pDisp Is WebBrowser1.object
Loop
     If Username.Text > "" And Password.Text > "" Then
            
            With WebBrowser1.Document
                .All("USERNAME").Value = Username.Text 
                .All("PASSWORD").Value = Password.Text 
                
                '.All("Submit").Click   
                '.All("ENTER").submit
                '.Forms(0).submit 'Use this to submit the info if the
                                        'one above it doesn't work.
                                                
                .myform.submit  
 ' myform is the name of the form on the webpage, 
'if you use the ones above, they may not work 
'and the third one seems to fire all the submits on the page. 
'You'll have to see which one works for each site
             End With
 call subroutine  'to parse whatever you want.
 End if

Interestingly, in the parsing arena, I  have noticed that  if I parse 
WebBrowser1.Document.body.innerText  or WebBrowser1.Document.body.innerHTML
on my desktop I get 

<INPUT value=6598 type=hidden name=CRN10><INPUT value=2802123 type=hidden name=CARRYUNAME>  

but when run on other computers (all running XP sp2 and above, some Vista)

<INPUT type=hidden value=6598 name=CRN10><INPUT value=2802123 type=hidden name=CARRYUNAME>

Notice that the type attribute is switched.  I have no idea why but it cost me alot of time to figure it out.  I basically have to check and see which one is returned.

----------


## Rally

Would you mind posting a sample App?

----------


## Giecha

Hello kleinma..

I've read a couple pages back and read that you were making a new example code for VS 2008. I wonder if you have finished it? Because I've checked the 2005 version and I think I could be really helped if it was on 2008  :Blush: 

I successfuly work out some part of it btw  :Smilie: 

Thanks

----------


## Hash1

Thanks, im glad I found this. Auto completing web forms is something im really interested in.

----------


## New_bee

Hi Kleinma,

if ur still following this thread... plz.. need ur help....  :Confused: 

not sure if this is where I should post  :Embarrassment:   but this quite similar to what i need.

so here it is:
i have a web application (using vs2008), the user will enter his username and password and a message and click on the submit button.
once the submit button is clicked, i need to open up a url in-memory (something like behind the scenes) without using the webbrowser control. once the url is opened, fill in the username and password supplied in my page, and submit the page, get the response, open a link which is in the page, which will redirect to a new page say page2.aspx, there i have a textbox for entering the message, i input the message the user entered in my application and then click the submit button in the page2.aspx, after clicking the button the page is posted and a message is displayed in a label in the page2.aspx which i need to capture and display it in a label on my application. then close the request that i made.
please help me with some sample code or point me in the direction i need to go in.. or some existing threads.

----------


## CAVU

Easiest way is to use the code above I provided on Dec 17. Also note that my code doesn't always work but I commented out the other methods for submitting.  Use the webbrowser control just don't show it or move it off screen.

You have to parse out the "link which is in the page" by using something like

InStr(1, WebBrowser1.Document.body.innerHTML, "courier") to find the position of the word "courier".  Then its just a matter of widdling it down to get your URL.  You can use a second webbrowser to launch the new link and so on.

Note:  Allow time for the page to load, use a timer control (or if you are using a separate webbrowser for each new run, you can use the webbrowser.documentcomplete function.

----------


## New_bee

Hi CAVU,
Thanks for the quick response.. but i guess.. yours is a windows app rite..  :Confused:  i need it for a web app.   :Embarrassment:

----------


## dedeblank

i hope u you upload vb.net 2008 version soon, been waiting for that release

----------


## Trusted

Hi Klein,

I am trying to make an Image Downloader. Your app on this post no.1 is got all the features that I need but I am using VB 2010.

Can you please make something in this version???

Thanks in advance,

Trusted

----------


## kleinma

Opening the sln file in VS2010 will convert it to that version. No need to post new code.

----------


## Scott_Atkins

this is exactly what im looking for but i cant open your attachment :-/ and iv got VS2010

----------


## sk8er_boi

wow... that was nice kleinma 

I think u can help me here, i'm trying to make a similar app : 

http://www.vbforums.com/showthread.p...getelementbyid

let me give u a quick overview

1. i open a url, search a particular text in a textbox on it (basically a ticket #)
2. when the search result loads the tkt # disaplayed will contain a link to open the ticket , i need to send "click" to this (open the link)
3. after the ticket is opened i need to send some data to combo boxes & textboxes

i have already done steps 1 & 3 but stuck @ step # 2 since the elementid of the search result is always going to vary, i tried it with a fixed ticket # & worked fine, how do i achieve step # 2 ?

this will save lot of my time with some repetitive tasks, pls help !

p.s. - i'm using VS2005

----------


## sk8er_boi

anyone ???

----------


## paxmanhorn9

Thanks very much for the info on this thread. I have learned much since finding it. Below is a line of HTML found in the current webpage that is giving me no small amount of 'heardburh'.
This line appears as the third (i think .item(2)) of the page. I am trying to invoke using 'click' as you do, but this is not a button. When rendered in the webbrowser control it appears to be a submit button, but, as you see, it is not.

(HTML element:

<input type="image" name="loginPrimeAccess" src="/images/btn_go_to_primeaccess_BEC0C2.gif" border="0" tabindex="3"><br>

In the code below I have commented out the TRY in order to see the error message.
Here is the code I have so far:

        Dim s As IHTMLElement

        Me.Browser.Document.GetElementsByTagName("Input").Item(0).SetAttribute("Value", "037882")
        Me.Browser.Document.GetElementsByTagName("Input").Item(1).SetAttribute("Value", "atrium")
        s = Me.Browser.Document.GetElementsByTagName("image").Item(1)
        'Try

        Me.Browser.Document.GetElementsByTagName("image").Item(2).InvokeMember("Click")
        'Catch
        'End Try

How can I get the login to go?
Thanks,
Gary

----------


## Scott_Atkins

> Thanks very much for the info on this thread. I have learned much since finding it. Below is a line of HTML found in the current webpage that is giving me no small amount of 'heardburh'.
> This line appears as the third (i think .item(2)) of the page. I am trying to invoke using 'click' as you do, but this is not a button. When rendered in the webbrowser control it appears to be a submit button, but, as you see, it is not.
> 
> (HTML element:
> 
> <input type="image" name="loginPrimeAccess" src="/images/btn_go_to_primeaccess_BEC0C2.gif" border="0" tabindex="3"><br>
> 
> In the code below I have commented out the TRY in order to see the error message.
> Here is the code I have so far:
> ...



Hi Gary,

Im glad you have found this thread useful, would you be able to tell me what Webpage your trying to login to so i can take a better look? 

Thanks

----------


## paxmanhorn9

The site is www.MyMls.com
Thanks,
Gary

----------


## make me rain

Klein just i want an advise which i worried from many days

is it possible to extract the data from a web page (.do file) to a data table
page contains a table 
and the name of the person,USERid,statement period

any advise please

----------


## escaleraroyal

i tried to do the submit button but it doesnt work because the source page doesn't have the submit button name or ID. can someone help me.


<td>
<label class="uiButton uiButtonConfirm" for="u847036_3">
<input value="Login" tabindex="4" type="submit" id="u847036_3" />
</label>
</td>


Code:
 DirectCast(GetCurrentWebForm.item("Login", 0), mshtml.HTMLButtonElement).click()

----------


## escaleraroyal

NVM 
I got it

 GetCurrentWebForm.submit()

----------


## escaleraroyal

I have a new issue. I show you the source code and my VB 2008 code. Basically I'm following what I did in my previous test to make it to work, however this website is more tricky. If someone could help me it would be great.

<div> 
			<span class="req">Posting Title:</span><br> 
			<input class="req" tabindex="1" type="text"
				name="U2FsdGVkX18xNzU1MTE3NY6yhOpP3KeiEsxnPNFPyI1_AiYA:ILvewO7Kx_XF :Big Grin: _4OTEL2-L5vlxg"
				id = "U2FsdGVkX18xNzU1MTE3NY6yhOpP3KeiEsxnPNFPyI1_AiYA:ILvewO7Kx_XF :Big Grin: _4OTEL2-L5vlxg"
				size="30" maxlength="70"
				value=""> 

		</div> 






            DirectCast(GetCurrentWebForm.item("U2FsdGVkX18xNzU1MTE3NY6yhOpP3KeiEsxnPNFPyI1_AiYA:ILvewO7Kx_XF :Big Grin: _4OTEL2-L5vlxg"), mshtml.HTMLTextAreaElement).value = txtData.Text

----------


## cancelor

The web site www.evony.com triggers the DocumentComplete event 5 times!

how can this be?

----------


## make me rain

i am ghaving a go button(s) here 
how can i simulate click event on the id go image here please

here is my peace of code

vb.net Code:
Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
         With Me.WebBrowser1
            .Document.All.Item("CrewID").InnerText() = "UBL1425"
            ' .Document.All.Item(13).InvokeMember("click")  ' no action 
            .Document.GetElementById("searchgo.gif").InvokeMember("click") ' no action
            '' button names used
            ''searchgo.gif
            '' "go"
         End With
    End Sub

 :wave:

----------


## ecktronic

Hi kleinma, I was reading your posts and this is just what I am looking to do.
I cannot seem to work out how to input my log in details to a desired website using the VB form.

I know I just need to get some code from the website and manipulate it into the VB code but I am not sure how to go about this.

I would really appreciate if you could point me in the right direction.

Thanks,
ecktronic

----------


## romanos8

I bought a script vbulletin for install it in my forum, now I have a discuzx forum on www.cristovideos.com/forum.php but I dont like this script. I trying to change my app from discuzx to vbulletin, I using this app for send pms to my members. The application is almost finished. only the last thing I need is that I can not fill the message. I still I have no forum installed and I am testing my app with another forum and I can not insert the message.

I trying with this code :

"wbForumpm.Document.Window.Frames("vB_Editor_001").Document.Body.InnerHtml = txtPMBody.Text"

and this code:
"'Body set
If Unit.GetAttribute("name") = "message" Then
Unit.SetAttribute("value", txtPMBody.Text)
End If"

But not work. I think that you can do it God willing .


I bought vbulletin 4 like http://www.webtalkforums.com/private...wpm&u=90020380 .

Thanks advanced.God bless you.

----------


## ecktronic

WebBrowser1.Navigate("URL of PAGE WITH MESSAGAE BOX")
WebBrowser1.Document.All("NAME OF MESSAGE BOX").InnerText = "TEXT TO SEND"
WebBrowser1.Document.GetElementById("NAME OF BUTTON").RaiseEvent("onclick")


That should work.  :Smilie: 
Let me know how you get on.

----------


## romanos8

> WebBrowser1.Navigate("URL of PAGE WITH MESSAGAE BOX")
> WebBrowser1.Document.All("NAME OF MESSAGE BOX").InnerText = "TEXT TO SEND"
> WebBrowser1.Document.GetElementById("NAME OF BUTTON").RaiseEvent("onclick")
> 
> 
> That should work. 
> Let me know how you get on.



Thanks, but I can not do this. This is the html code.



```
<!-- message area -->

			

<!-- / Editor Scripts --><div id="vB_Editor_001" class="blockrow texteditor">
	<div class="editor">
		<div class="editor_textbox_container smilie">
				<div class="editor_textbox editor_textbox_smilie">
					<textarea id="vB_Editor_001_editor" name="message" rows="8" cols="60" autocomplete="off" tabindex="1"></textarea>


				</div>
		</div>

		
		<div class="editor_smiliebox">
			

<ul class="smiliebox floatcontainer" id="vB_Editor_001_smiliebox">
	
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/frown.png" id="vB_Editor_001_smilie_1209" alt=":(" title="Frown" border="" />
		</div>
	</div>
</li>

<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/mad.png" id="vB_Editor_001_smilie_1210" alt=":mad:" title="Mad" border="" />
		</div>
	</div>
</li>
<li>
	<div class="table">
		<div class="tablecell">

			<img src="images/smilies/redface.png" id="vB_Editor_001_smilie_1211" alt=":redface:" title="Redface" border="" />
		</div>
	</div>
</li>
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/rolleyes.png" id="vB_Editor_001_smilie_1212" alt=":rolleyes:" title="Rolleyes" border="" />
		</div>
	</div>

</li>
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/smile.png" id="vB_Editor_001_smilie_1213" alt=":)" title="Smile" border="" />
		</div>
	</div>
</li>
<li>
	<div class="table">
		<div class="tablecell">

			<img src="images/smilies/tongue.png" id="vB_Editor_001_smilie_1214" alt=":p" title="Tongue" border="" />
		</div>
	</div>
</li>
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/wink.png" id="vB_Editor_001_smilie_1215" alt=";)" title="Wink" border="" />
		</div>
	</div>

</li>
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/biggrin.png" id="vB_Editor_001_smilie_1205" alt=":D" title="Biggrin" border="" />
		</div>
	</div>
</li>
<li>
	<div class="table">
		<div class="tablecell">

			<img src="images/smilies/confused.png" id="vB_Editor_001_smilie_1206" alt=":confused:" title="Confused" border="" />
		</div>
	</div>
</li>
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/cool.png" id="vB_Editor_001_smilie_1207" alt=":cool:" title="Cool" border="" />
		</div>
	</div>

</li>
<li>
	<div class="table">
		<div class="tablecell">
			<img src="images/smilies/eek.png" id="vB_Editor_001_smilie_1208" alt=":o" title="Eek" border="" />
		</div>
	</div>
</li>
</ul>

		</div>

		
	</div>
</div>

<input type="hidden" name="wysiwyg" id="vB_Editor_001_mode" value="1" />
			<!-- / message area -->
```

Also this code : 


<body class="forum" contenteditable="true" spellcheck="true" style="height: auto;">
<br type="_moz">
</body>


I already used:
message
vB_Editor_001_editor


But not work. Thanks in advanced.

----------


## ecktronic

Oops, I didn't realise you were using HTML sorry!

Hope you manage to figure this out.

----------


## romanos8

No, I am using VB 2010 but this is the html of the vbulletin, I need help for find the right html element to use it in my app.




> Oops, I didn't realise you were using HTML sorry!
> 
> Hope you manage to figure this out.

----------


## mmikes

Hi, I am new to this- I have a VB.net project in VS2005, and I added an HTML.htm window form to it. I put a button the form and I would like to have the onclick event run a vb sub. I know I need an event handler or the sub, but how do I get the name of the html button in the vb addhandler statement?

----------


## piklio

Hi kleinma
i saw ur app . thats amazin and works fine for me !
but now i have question.
i want to click on some ads on site . but i cant find this as links in your application's getlinks() sub .
can u download this attachment and learn me how to click on this via vb.net ?

*i attached html source . but forum rules deny it . plz download attachment and then rename it from test.txt to test.html !*

thanks in advance

----------


## piklio

bump ! 
:d

----------


## afdoal

i get the picture on website, then i need my application auto text values of the picture... 
can u help me with this problem??

this my code for get the image:


```
        Dim doc As IHTMLDocument2 = WebBrowser1.Document.DomDocument
        Dim imgRange As IHTMLControlRange = CType(doc.body, HTMLBody).createControlRange
        For Each img As IHTMLImgElement In doc.images
            If img.GetAttribute("src").ToString.Contains("image.php") Then
                imgRange.add(img)
                imgRange.execCommand("Copy", False, Nothing)
                PictureBox1.Image = Clipboard.GetDataObject.GetData(DataFormats.Bitmap)
                Exit For
            End If
        Next
```



My  Problen on Thread
http://www.vbforums.com/showthread.p...54#post4111754

----------


## coolcurrent4u

@afdoal you need to use a decaptcha service or delve into image processing (OCR)

Can anyone help on how to simulate typing, which is a combination of onkeydown, onkeypress and onkeyup events? 

regards

----------


## mrducnt

@kleinma:
I have some trouble determining the completed event.



```
' Load the url
    Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim orgurl As String = "url"
        wb.Navigate(orgurl)
    End Sub

'Document completed event
    Private Sub webBrowser_DocumentCompleted(sender As Object, e As AxSHDocVw.DWebBrowserEvents2_DocumentCompleteEvent) Handles wb.DocumentComplete
'Change the value in the txt box, and submit  
   
DirectCast(GetCurrentWebDoc.getElementById("ctl00_mainContent_Live3Price1_NEW_wdcDate_dateInput_TextBox"), mshtml.HTMLInputElement).value = "22/06/2012"
        DirectCast(GetCurrentWebDoc.getElementById("ctl00_mainContent_Live3Price1_NEW_Button1"), mshtml.HTMLInputElement).click()
'AFTER submit, content will be loaded. The submit button call AJAX to load data into table. Url unchanged.
'But the ready state already be "Complete"
'I'v tried WebBrowserReadyState.Complete and SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE , but get the same result, their state will be "Complete", even when browser still loading the content.
        If wb.ReadyState = WebBrowserReadyState.Complete Then
            MessageBox.Show("Done")
        End If
    End Sub
```

How to check if browser has completely loaded (after AJAX)?

I have to parse the source code (after AJAX), and need to check the state of browser

----------


## r3z1

Hi all , 

can any one help me with  this : 

a program takes value from txt document and fills it in to online registration form. so i dont need it to do in manualy over and over again . I just change the txt file every time i need to create new . 

lets say . "mr bob brown". have to be filled in to online registration form . lets say register.jabber.org. 
so i just need to pres button "register" on a webpage . or better the program to have a button too  :Smilie:  after fill execute (but offcourse it will be hard to avoid the HUMAN CHECK box ) but still i need help in this  :Smilie:  I dont need passing by check box . i need to auto fill . "roboform" similer to this but simpler .

----------


## Nolan

I need help filling out the region and the category this web page. http://www.inetgiant.com/item/new  It wants you to physically click it. I got everything else i need to work. Please help.

----------


## ibennz

Was wondering if you updated this to 2005 browser. I use default webbrowser (extended) that I found on some scratch code. Its actually 2005 IE. It doesn't want to convert my html source to mshtml . 


```
     Try
         
            Dim GetCurrentWebDoc As mshtml.HTMLDocument = DirectCast(wb.Document, mshtml.HTMLDocument)
            Dim MyDiv As mshtml.HTMLDivElement = DirectCast(GetCurrentWebDoc.getElementsByTagName("img"), mshtml.HTMLDivElement)
            If MyDiv.getAttribute("className") = "vam hand" Then
                MessageBox.Show(MyDiv.getAttribute("onclick"))

            End If

        Catch
            MsgBox(ErrorToString, MsgBoxStyle.Critical)
        End Try
```

----------


## BlitzMX

SOLVED
VS 2010 converts automaticly.





> All the time I see people asking how to autofill in forms on webpages or how to click a button in a webpage that is hosted in the webbrowser control, via VB code.
> 
> It is really not all that difficult, once you get around the casting of types to the correct kind when using the COM reference.
> 
> This example project highlights the following manipulations (as well as opening the door to manipulate just about anything on a webpage that is possible)
> 
> * Getting a value of an HTML input element
> * Setting a value of a HTML input element
> * Getting a value of an HTML text area
> ...


Hello

This looks to be exactly what i need to start on a tool at the company i work for, do you have it on VB 2010? i am having dificulties to open it.
Any idea how to solv this?

Thank you any way, im sure i´ll find a way to make it work.
Best regards.
Blitz

----------


## titlemanager

The project page "TestPage.htm" shows signs of a budding star in web design. Some real layout talent there. 

On a more serious note, I'm sure I speak for many when I say thank you. Your post is well written and it has obviously helped many of us who still have a lot to learn. I've used your code as a starting point on more than one project. Again, thank you kleinma.

----------


## hancejws

Nice 
 :Smilie:

----------


## romanos8

I need to fill this text area but the value of class and ID changes:

<div aria-labelledby="255" role="textbox" g_editable="true" class="df b-K b-K-Xb URaP8 editable" id=":78.f" contenteditable="true"></div>

How can I have success ?

----------


## dolluatdoll

Dear every predecessors,

This is a super helpful thread. I am not sure if anyone still following the thread, I hope there is a little chance somebody could help :Stick Out Tongue: 

Right now, I am trying to fill forms on website, I did it with "Sendkeys", but by reading #196, it is not appropriate.



```
        
        WebBrowser1.Navigate("https://mybank.icbc.com.cn/icbc/enperbank/index.jsp")
        WaitForPageLoad()
        TextBox1.Text = WebBrowser1.Url.ToString

        SendKeys.Send("UserABC")
        SendKeys.Send("{TAB}")
        SendKeys.Send("Password")
```



```
    Private Property pageready As Boolean = False

#Region "Page Loading Functions"
    Private Sub WaitForPageLoad()
        AddHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
        While Not pageready
            Application.DoEvents()
        End While
        pageready = False
    End Sub

    Private Sub PageWaiter(ByVal sender As Object, ByVal e As WebBrowserDocumentCompletedEventArgs)
        If WebBrowser1.ReadyState = WebBrowserReadyState.Complete Then
            pageready = True
            RemoveHandler WebBrowser1.DocumentCompleted, New WebBrowserDocumentCompletedEventHandler(AddressOf PageWaiter)
        End If
    End Sub

#End Region
```

I believe that the login form is an ActiveX control ttps://mybank.icbc.com.cn/icbc/enperbank/index.jsp
The source code of the password field:


```
<OBJECT onkeyup="getfocus1('KeyPart', event);detectCapsLock('logonform','safeEdit1',500,300,400,'logontb');" onfocus="detectCapsLock('logonform','safeEdit1',500,300,400,'logontb')" onblur="closeCapTip('logonform','safeEdit1')" id=safeEdit1 codeBase="/icbc/newperbank/AxSafeControls.cab#version=1,0,0,13" classid=CLSID:73E4740C-08EB-4133-896B-8D0A7C9EE3CD width=145 height=21><PARAM NAME="_cx" VALUE="3836"><PARAM NAME="_cy" VALUE="556"></OBJECT>
```

Is there a way to pass value into the password field with it ID/name??

Thank you for any advice!!!

----------

