-
Feb 13th, 2008, 04:50 PM
#241
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.
-
Feb 14th, 2008, 02:10 PM
#242
New Member
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
-
Feb 15th, 2008, 02:27 AM
#243
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
-
Feb 18th, 2008, 12:45 AM
#244
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Feb 18th, 2008, 10:15 AM
#245
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Feb 18th, 2008, 10:16 AM
#246
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Did anyone else still need help with something here?
-
Feb 18th, 2008, 01:15 PM
#247
New Member
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.
-
Feb 18th, 2008, 08:48 PM
#248
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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?
-
Feb 19th, 2008, 02:59 AM
#249
Member
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,
-
Feb 19th, 2008, 10:19 AM
#250
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
nvm thanks
I found a way..
-
Feb 22nd, 2008, 07:01 AM
#251
New Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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
-
Feb 22nd, 2008, 10:39 AM
#252
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
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.
-
Mar 10th, 2008, 03:22 AM
#253
New Member
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
-
Mar 17th, 2008, 07:29 AM
#254
New Member
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....
Last edited by Delicioso; Mar 18th, 2008 at 04:02 AM.
-
Mar 18th, 2008, 07:01 AM
#255
New Member
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
Last edited by Delicioso; Mar 18th, 2008 at 07:09 AM.
-
Mar 24th, 2008, 06:08 PM
#256
New Member
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?
-
Mar 24th, 2008, 08:31 PM
#257
Member
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?
-
Mar 26th, 2008, 03:42 PM
#258
New Member
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.
-
Mar 30th, 2008, 09:47 PM
#259
Addicted Member
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...
-
Mar 31st, 2008, 07:17 PM
#260
New Member
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?
-
Apr 2nd, 2008, 04:30 PM
#261
Hyperactive Member
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
-
Apr 2nd, 2008, 08:09 PM
#262
Hyperactive Member
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........
-
Apr 2nd, 2008, 09:06 PM
#263
Hyperactive Member
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
-
Apr 3rd, 2008, 09:49 AM
#264
New Member
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
-
Apr 3rd, 2008, 05:22 PM
#265
New Member
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.
-
Apr 8th, 2008, 10:17 PM
#266
New Member
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.
-
May 3rd, 2008, 08:01 AM
#267
Member
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
Last edited by razohad; May 4th, 2008 at 07:40 AM.
-
May 3rd, 2008, 08:19 PM
#268
Member
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
-
May 4th, 2008, 04:10 PM
#269
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
-
May 7th, 2008, 02:04 PM
#270
New Member
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
Last edited by Amsterdam; May 7th, 2008 at 02:44 PM.
-
May 7th, 2008, 04:16 PM
#271
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.
-
May 7th, 2008, 04:18 PM
#272
Re: How to find a span tag value
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.
-
May 8th, 2008, 08:00 PM
#273
Member
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
-
May 9th, 2008, 10:23 AM
#274
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.
-
May 9th, 2008, 10:31 AM
#275
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.
-
May 9th, 2008, 12:38 PM
#276
Member
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 :<
-
May 9th, 2008, 12:42 PM
#277
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?
-
May 9th, 2008, 08:12 PM
#278
Member
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
first let me say thanks for the reply.
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?
-
May 9th, 2008, 10:00 PM
#279
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", "")
-
May 11th, 2008, 05:01 AM
#280
Member
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 .
Last edited by razohad; May 11th, 2008 at 05:18 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|