-
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.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Hi Kleinma,
I am using the .net from VB 2005 Webbrowser control,
mayby you can take a closer look at post #293 there is al the code and in post #294 you replayed to that one, there is also the form where i want to post the data :)
[Respect]
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
does it do anything at all when your code runs?
You are doing 3 things in your code, filling in 2 textbox fields, and clicking 1 button.
So do any of those occur? or simply nothing occurs?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
This is what intelligence say when i typed those 3 lines:
Error 1 Overload resolution failed because no accessible 'Item' accepts this number of arguments.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
if you are using the managed browser control (the .NET one built into .NET 2.0 and up), I would think your code should look like this:
Code:
WebBrowser1.Document.Forms(0).All("email").SetAttribute("value", "[email protected]")
WebBrowser1.Document.Forms(0).All("password").SetAttribute("value", "fakepassword")
WebBrowser1.Document.Forms(0).InvokeMember("submit")
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Nice great, looking for this for weeks now.
Already got a bill from www.Google.com :)
I still get a error but basics works.
the email and login are posted than the login is activated,
on the second page there is en age question witch olso has a submite buttom
after giving the age answere (Manual) VB gave this error: Object reference not set to an instance of an object. ON LINE: WebBrowser1.Document.Forms(0).All("email").SetAttribute("value", "[email protected]")
Very strange.
But still lot's of thanks.
[Respect]
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
well if its asking an age question, why is the field you are referencing called "email" still???
Also make sure that it is the FIRST form on the page. If there are more than 1 form, you need to use another index instead of 0 (or you can reference the form by its actual string name if it has one)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
They strange thing is that i am already login and showing the seconde page i also entered the age value en clicked the next button as the error occors.
This is the code:
Code:
Private Sub
WebBrowser1.Document.Forms(0).All("email").SetAttribute("value", "[email protected]")
WebBrowser1.Document.Forms(0).All("password").SetAttribute("value", "fakepassword")
WebBrowser1.Document.Forms(0).InvokeMember("submit")
End Sub
It looks to me that the sub is already ended because those 3 line's of code already done there thing :)
No there is no email on the seconde page.
I will keep looking and trying :)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
where are you calling this code from? The DocumentCompleted event?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
hi kleinma, i know ur very busy but i've lookd at ur manipulate html program and it's helped me a lot up until now. i'm trying to grab some data from a text box and also click a submit button but the problem i'm having is that they are embedded in a table and the html code looks like this :
Quote:
<td>
<form action="do.php" method="post"><input type="hidden" name="fb_sig_time" value="1212024219.9303" /><input type="hidden" name="fb_sig_added" value="1" /><input type="hidden" name="fb_sig_user" value="" /><input type="hidden" name="fb_sig_profile_update_time" value="1211595353" /><input type="hidden" name="fb_sig_session_key" value="3e0cbd386d76f1163cf3c180-277622" /><input type="hidden" name="fb_sig_expires" value="0" /><input type="hidden" name="fb_sig_api_key" value="afe4c25ae28531b4785fe2a9a34fd1fb" /><input type="hidden" name="fb_sig" value="9047b3ba4d47016bb5dfcdcf7364c06d" />
Deposit Amount: <input type="text" name="deposit_amount" value="0" />
<input type="hidden" name="action" value="deposit" />
<input type="submit" value="Deposit" />
</form>
<p class="note">A 10% safehouse fee will be taken out of all incoming funds.</p>
</td>
</tr>
</table>
i'm really trying to deal with the deposit amount. i need to be able to read whats in the text box and also click the submit button.
i've been using:
DirectCast(GetCurrentWebForm.item(), mshtml.HTMLInputElement).value but it doesn't seem to work in this case
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
DirectCast(GetCurrentWebForm.item(), mshtml.HTMLInputElement).value
This isn't even valid syntax. You aren't actually grabbing any specific item with this code..
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
well for instance i used ur code for this:
DirectCast(GetCurrentWebForm.item("email"), mshtml.HTMLInputElement).value = emtxt.Text
Quote:
<label for="email" id="label_email">Email:</label><input type="text" class="inputtext" name="email" value="" id="email" size="20" onkeypress="login_form_change()" />
and that works for the login page but i don't know what to use for the above case because there are no id's and i'm not sure what to use in order to grab what i want.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
nevermind i figured it out :)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by kleinma
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.
Hey man,
I was wondering if the new version you spoke about above would be in VB2008? And if so, if you were close to releasing it?
Thanks for your time
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
i have a question, how can i get the axwebbrowser control on a machine running xp? i've tried to reference the shdocvw.dll and it didn't do anything. i also tried to reference the two dll's from kleinma's webmanipulation project but still i can't get the control to show up when i go to chose toolbox items.
ugh, for some reason i always figure things out after i post it...
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by Franklin
Hey man,
I was wondering if the new version you spoke about above would be in VB2008? And if so, if you were close to releasing it?
Thanks for your time
It is almost done. The project itself will be done in a 2008 solution/project, however I target the .NET 2.0 framework.
This is because there is no difference between the browser control in .NET 2.0 and .NET 3.x so by targetting 2.0, you maximize compatibility.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by kleinma
It is almost done. The project itself will be done in a 2008 solution/project, however I target the .NET 2.0 framework.
This is because there is no difference between the browser control in .NET 2.0 and .NET 3.x so by targetting 2.0, you maximize compatibility.
Thank you for the info and the fast response. I look forward to seeing it greatly :)
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
any idea where i can find example of
filling a form using httprequest code?
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by razohad
any idea where i can find example of
filling a form using httprequest code?
Hi razohad, i have no idea about this but perhaps you could help me.
Can you give some orientation about activate POP3 forwarding on gmail settings from the vb .net code with the axwebbrowser.
I can create an account and log into but i can't check the POP3 radiobutton and saves the changes (the gmail code about it look so strange).
Can you help me? thanks a lot.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by razohad
any idea where i can find example of
filling a form using httprequest code?
You can't fill a form with an httprequest. You can however post data to a URL similar in a way that when you fill out an HTML form and click submit, the data is posted to the URL that is in the action attribute of the <form> tag. This also requires the method of the form tag is post, and not get, otherwise you would be dealing with querystrings and not form posts.
-
Re: Manipulate/Change/Form Fill data in webpages using the Webbrowser control
Quote:
Originally Posted by kleinma
You can't fill a form with an httprequest. You can however post data to a URL similar in a way that when you fill out an HTML form and click submit, the data is posted to the URL that is in the action attribute of the <form> tag. This also requires the method of the form tag is post, and not get, otherwise you would be dealing with querystrings and not form posts.
any idea where i can find an example ?
and thanks