-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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..
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
how should i parse the webpage to get to the button..
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Alrighto...
You are amazing..
Thank you so much.. would work on it..
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
:eek2: it didn't work either, do you think HTTPwebreqest might be helpful, for my problem..
-
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
Code:
<input type="submit" class="button" value="Save Signature" accesskey="s" tabindex="1" />
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by 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.
How about this, instead of doing that...
Code:
<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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
I dont think that will work, but i suppose you could try it.
I still think you should just call the forms .Submit method.
-
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
-
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.
-
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.
-
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
-
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.
-
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
here
Code:
DirectCast(GetCurrentWebDoc.getElementById("MakeAndModelSearch1_m_search"), mshtml.HTMLInputElementClass).click()
-
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?
-
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.
-
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
-
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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.
-
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..
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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
-
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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 :)
-
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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.
-
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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.
-
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:
Quote:
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)
-
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.
-
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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.
-
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.