Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Code:
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-
Last edited by coheed; Mar 14th, 2007 at 06:50 AM.
Reason: vbcode
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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...
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Last edited by ArmchairAthlete; May 15th, 2007 at 08:52 AM.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Last edited by ArmchairAthlete; May 18th, 2007 at 08:38 AM.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
as requested:
All I can debug is that my Vb 2005 Express does not know "mshtml"
Looking fwd to your reply
Thanks //Gibbo
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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:
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:
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.
Last edited by roiegat; Jun 27th, 2007 at 09:02 AM.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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.
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.
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Originally Posted by 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
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.