|
|||||||
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
|
#241 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 18,596
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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..
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com - Free MSDN Subscription Contest -=Matt=- |
|
|
|
|
|
#242 |
|
New Member
Join Date: Mar 07
Posts: 14
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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!)... Code:
Last edited by JFitz : Dec 14th, 2007 at 12:16 PM. |
|
|
|
|
|
#243 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 18,596
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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: Code:
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.
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com - Free MSDN Subscription Contest -=Matt=- |
|
|
|
|
|
#244 |
|
New Member
Join Date: Mar 07
Posts: 14
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 ![]() |
|
|
|
|
|
#245 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 18,596
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com - Free MSDN Subscription Contest -=Matt=- |
|
|
|
|
|
#246 |
|
New Member
Join Date: Mar 07
Posts: 14
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Ah ok great.
Can you help me with one final question, eh, well can I be greedy and ask for two!? 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 ![]() |
|
|
|
|
|
#247 |
|
New Member
Join Date: Apr 07
Posts: 10
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 Last edited by ed08724 : Feb 12th, 2008 at 04:30 PM. |
|
|
|
|
|
#248 |
|
Member
Join Date: Feb 08
Posts: 39
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 |
|
|
|
|
|
#249 |
|
New Member
Join Date: Oct 07
Posts: 2
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 who’s 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 |
|
|
|
|
|
#250 |
|
New Member
Join Date: Apr 07
Posts: 10
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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. |
|
|
|
|
|
#251 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 18,596
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com - Free MSDN Subscription Contest -=Matt=- |
|
|
|
|
|
#252 |
|
New Member
Join Date: Apr 07
Posts: 10
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 |
|
|
|
|
|
#253 |
|
New Member
Join Date: Apr 07
Posts: 10
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Nevermind. I solved it.
|
|
|
|
|
|
#254 | |
|
Member
Join Date: Feb 08
Posts: 39
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
still having troubles with setting values to rdobtn and checkbox.. can someone advise. |
|
|
|
|
|
|
#255 | |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 18,596
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
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. Code:
Then you need to call this code like so: Code:
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.
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com - Free MSDN Subscription Contest -=Matt=- |
|
|
|
|
|
|
#256 |
|
Moderator.NET
Join Date: Nov 01
Location: NJ - USA (Near NYC)
Posts: 18,596
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Did anyone else still need help with something here?
__________________
Using VB.NET 2008/.NET 2.0/3.5 * Please mark you thread resolved using the Thread Tools above ![]() PLEASE INDICATE WHAT VERSION OF VB YOU USE!!!!!!!!!!! * If you found a post useful then please Rate it! Code Bank:Manipulate HTML Page content in the Web Browser Control from VB - Drag Drop from Windows into Win Form - Launch new default browser instance to open URL - Display Internet Image in Picturebox - Download Files From Web With Progress Bar - IP Textbox User Control - Installing .NET Framework with INNO Setup ZerosAndTheOne.com - Free MSDN Subscription Contest -=Matt=- |
|
|
|
|
|
#257 |
|
New Member
Join Date: Oct 07
Posts: 2
![]() |
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 o |