-
Aug 28th, 2007, 03:57 AM
#161
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Aug 28th, 2007, 01:48 PM
#162
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Aug 29th, 2007, 10:41 AM
#163
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
thank you very much
I had cracked 1&2 and was stubling over 3.
Very helpful, much appreciated.
-
Aug 30th, 2007, 10:02 AM
#164
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Code:
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.
Code:
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
-
Aug 30th, 2007, 12:24 PM
#165
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Aug 30th, 2007, 02:21 PM
#166
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Aug 31st, 2007, 09:07 AM
#167
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
here
Code:
DirectCast(GetCurrentWebDoc.getElementById("MakeAndModelSearch1_m_search"), mshtml.HTMLInputElementClass).click()
-
Sep 1st, 2007, 08:26 AM
#168
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?
-
Sep 2nd, 2007, 11:05 AM
#169
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Sep 2nd, 2007, 02:40 PM
#170
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
edit: btw, this is for the ebay login page, here
https://signin.ebay.co.uk/ws/eBayISA...k/&_trksid=m37
Last edited by 4xzer0; Sep 2nd, 2007 at 04:18 PM.
-
Sep 3rd, 2007, 05:32 AM
#171
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Sep 3rd, 2007, 10:02 AM
#172
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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
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.
-
Sep 3rd, 2007, 11:38 AM
#173
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Kleinma can you help me please with the ebay login?
I am using visual studio 2005..
-
Sep 3rd, 2007, 04:06 PM
#174
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 4xzer0
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?
-
Sep 3rd, 2007, 04:35 PM
#175
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by kleinma
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)
-
Sep 4th, 2007, 09:15 AM
#176
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 4xzer0
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
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
-
Sep 4th, 2007, 10:38 AM
#177
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Sep 4th, 2007, 11:11 AM
#178
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by kleinma
seems to work fine for me using this code
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
Oh, thanks a lot kleinma !
this code works great
Last edited by 4xzer0; Sep 4th, 2007 at 12:39 PM.
-
Sep 4th, 2007, 02:42 PM
#179
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Sep 4th, 2007, 06:20 PM
#180
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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.
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?
-
Sep 4th, 2007, 06:21 PM
#181
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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
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.
-
Sep 4th, 2007, 06:35 PM
#182
Lively Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Sep 4th, 2007, 06:59 PM
#183
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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
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)
Code:
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:
Code:
With GetCurrentWebForm("mainform")
DirectCast(.item("address"), mshtml.HTMLInputElement).value = "Value Here"
End With
Which works fine.
-
Sep 4th, 2007, 07:06 PM
#184
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by kleinma
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.
-
Sep 7th, 2007, 07:35 AM
#185
Lively Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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.
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.
-
Sep 7th, 2007, 08:38 AM
#186
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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)
-
Sep 7th, 2007, 09:58 AM
#187
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Sep 7th, 2007, 10:00 AM
#188
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
I can't really help with that information. You would need to provide more and I will see if I can help or not.
-
Sep 7th, 2007, 09:42 PM
#189
Lively Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by kleinma
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.
-
Sep 8th, 2007, 10:12 AM
#190
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
there is also a "browse" tab. Use that instead of the .NET tab when setting the reference and browse the the system32 folder.
-
Oct 1st, 2007, 07:39 PM
#191
Junior Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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.
Code:
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.
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:
Code:
<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:
Code:
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!
-
Oct 2nd, 2007, 09:38 AM
#192
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Oct 2nd, 2007, 12:51 PM
#193
Junior Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
hi Kleinma, thanks for your response. I added a parameter to the code to make it like the following:
Code:
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!!!!!
-
Oct 2nd, 2007, 01:04 PM
#194
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
glad to hear you got it working.
-
Oct 5th, 2007, 11:31 AM
#195
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Oct 5th, 2007, 12:11 PM
#196
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Oct 18th, 2007, 04:31 PM
#197
Addicted Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Code:
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.
-
Oct 23rd, 2007, 07:14 PM
#198
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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:
Code:
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
My Languages: English, VB 2005, Perl
My Hobbies: Code, Photoshop, Skateboarding, Video Games, Flying, Cars(modification), Airbrushing, Electronic music DJing, and production.
-
Oct 23rd, 2007, 07:52 PM
#199
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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.
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?
My Languages: English, VB 2005, Perl
My Hobbies: Code, Photoshop, Skateboarding, Video Games, Flying, Cars(modification), Airbrushing, Electronic music DJing, and production.
-
Oct 23rd, 2007, 08:20 PM
#200
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
My Languages: English, VB 2005, Perl
My Hobbies: Code, Photoshop, Skateboarding, Video Games, Flying, Cars(modification), Airbrushing, Electronic music DJing, and production.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|