-
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..
-
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:
<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;
-
1 Attachment(s)
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:
'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.
-
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 :D
-
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.
-
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!? :o
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 :afrog:
-
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
-
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
-
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
-
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.
-
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.
-
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by 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
still having troubles with setting values to rdobtn and checkbox..
can someone advise.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by akagi07
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.
Code:
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:
Code:
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Did anyone else still need help with something here?
-
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 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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by kleinma
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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, :)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
nvm thanks
I found a way.. ;)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by kleinma
Did anyone else still need help with something here?
Yep, I w8 for you to make the programm for vb 2008:)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by rubiks cube
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 :
Code:
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 :
Code:
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....
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Code:
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Code:
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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...
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Hi to all, im trying to use the hightlight function for my own application but im getting errors :
this its the code i use
Code:
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
does anyone know whats wrong with that ?? im using a normal webbrowser control, i dont know whats wrong........
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
i was playing with the project that kleinma uploaded, at the form load event
i changed this code :
Code:
wb.Navigate(Application.StartupPath & "\TestPage.htm")
to
Code:
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
So this is what I've come up with....
Code:
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...
Code:
<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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
-
How to find a span tag value
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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: How to find a span tag value
Quote:
Originally Posted by 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
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
kleinma
can you plz help with my problem
i posted 4 posts above
thanks
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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 :<
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
first let me say thanks for the reply.
Quote:
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
Code:
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?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
Code:
curElement.SetAttribute("disabled", "kleinma")
and when you want to remove this specific attribute, you pass an empty string, which enables the control
Code:
curElement.SetAttribute("disabled", "")
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
once again your right. :)
this work
Code:
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 .
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
ok thanks i get the idea.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Hello kleinma,
Can i get some help from you?
I am new at vs2005 but have some old programing experiance (Clipper,Enz) :)
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 :)
Code:
Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
Dim Varemail = "[email protected]"
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:
Code:
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.
Code:
<!-- 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)
Code:
Response.Write("<FORM Target='2escreen' method='post' Action='http://www.fake.nl/fake/login2e.php'>")
Response.Write("<INPUT Name='email' value='[email protected]' 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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
Code:
<input type="button" class="blackbutton" onclick="editorAjax(this,'preview=0&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
Code:
WebBrowser1.Document.GetElementById("editor_submit").InvokeMember("click")
nothing happens. I also tried invoking the script with
Code:
Dim ObjArr(2) As Object
ObjArr(0) = CObj(New String("editor_submit"))
ObjArr(1) = CObj(New String("preview=0&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
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
vb Code:
Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
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:(
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by Ranex
vb Code:
Private Sub Button_Start_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button_Start.Click
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.