protootorp 09-11-2009, 09:39 PM im curious as how to click a button in webbrowser. normally
webbrowser1.document.all("submit").click
works.
but I think this little piece changes the whole situation.
<TD><SPAN class=cool_button><INPUT class=cool_stuff value=take_out type=submit name=do></SPAN></TD></TR></TBODY></TABLE></FORM></TD></TR>
I think the class is making it not click it...?
I tried changing the html and removed the class, then saved it as a html doc,opened the doc in webbrowser and clicked the button myself just to see if it would work, but it didn't.
I cannot think of another way to make this work.
webbrowser1.document.all("do").click
webbrowser1.document.all("take_out").click
does not work. I know those functions do work, because i log into the site.
but dont work for that specific button.
any help would be great. I'm working with visual basic 6
Cerian Knight 09-11-2009, 11:15 PM Perhaps enumeration is the way to find it. This example might help:
http://www.xtremevbtalk.com/showthread.php?t=285874
This thread reminds me that .Submit is a possible option and also that Frames might make deeper searches through the COM structure necessary (set a breakpoint an burrow down through 'View/Locals Window'):
http://www.xtremevbtalk.com/showthread.php?t=279675
protootorp 09-11-2009, 11:57 PM maybe I could do it through javascript? webbrowser1.navigate ("javascript:thejavascript") ?
The first example you showed me the link to made me think, maybe i have the same problem as him, but the code you gave him doesn't seem to work for me still.
here is the HTML to the part with the buttons.
I assume the rest of the HTML isn't really needed.
<form action="remote/html_server.php?xw_controller=bank&xw_exp_sig=c3758e1415a47ffdb9b264e8 e220f946&xw_time=1252733929&xw_action=withdraw&xw_city=1&tmp=e8fa5c518 fe08761a0cd7b4bd2ce96fa" method="post" onsubmit="fbjs_sandbox.instances.a10979261223.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,10979261223),function(a10979261223_event) {a10979261223_submitForm('inner_page', 'remote/html_server.php?xw_controller=bank&xw_exp_sig=c3758e1415a47ffdb9b264e8 e220f946&xw_time=1252733929&xw_action=withdraw&xw_city=1&tmp=e8fa5c518 fe08761a0cd7b4bd2ce96fa', $FBJS.ref(this), 1); return false;},10979261223],new fbjs_event(event));" id="app10979261223_bank_withdraw" fbcontext="a3f5f23cdda5"><input type="hidden" name="fb_sig_locale" value="en_US" /><input type="hidden" name="fb_sig_in_new_facebook" value="1" /><input type="hidden" name="fb_sig_time" value="1252733930.2628" /><input type="hidden" name="fb_sig_added" value="1" /><input type="hidden" name="fb_sig_profile_update_time" value="1251178770" /><input type="hidden" name="fb_sig_expires" value="1252738800" /><input type="hidden" name="fb_sig_user" value="100000164811549" /><input type="hidden" name="fb_sig_session_key" value="2.GJ1_wUgWsBaF_0EmahY_Zg__.3600.1252738800-100000164811549" /><input type="hidden" name="fb_sig_ext_perms" value="status_update,photo_upload,video_upload,create_note,share_item,auto_pu blish_short_feed,publish_stream,auto_publish_recent_activity" /><input type="hidden" name="fb_sig_api_key" value="63eade489b31633f81a5cd776197cc65" /><input type="hidden" name="fb_sig_app_id" value="10979261223" /><input type="hidden" name="fb_sig" value="725a81fb560e4e9a89b51b53c3334a1d" /><input type="hidden" name="ajax" value="1" /><input type="hidden" name="xw_user_name" value="[["John","Smith"]]" /> <table><tr>
<td>Amount: <input name="amount" type="text" style="width: 140px;" /></td>
<td><span class="sexy_button"><input type="submit" class="sexy_cash" name="do" value="Withdraw" /></span></td>
</tr></table>
</form> </td>
<td>
<form action="remote/html_server.php?xw_controller=bank&xw_exp_sig=c3758e1415a47ffdb9b264e8 e220f946&xw_time=1252733929&xw_action=deposit&xw_city=1&tmp=6e0bf986a8 e1fb7eadc350faec89b489" method="post" onsubmit="fbjs_sandbox.instances.a10979261223.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,10979261223),function(a10979261223_event) {a10979261223_submitForm('inner_page', 'remote/html_server.php?xw_controller=bank&xw_exp_sig=c3758e1415a47ffdb9b264e8 e220f946&xw_time=1252733929&xw_action=deposit&xw_city=1&tmp=6e0bf986a8 e1fb7eadc350faec89b489', $FBJS.ref(this), 1); return false;},10979261223],new fbjs_event(event));" id="app10979261223_bank_deposit" fbcontext="a3f5f23cdda5"><input type="hidden" name="fb_sig_locale" value="en_US" /><input type="hidden" name="fb_sig_in_new_facebook" value="1" /><input type="hidden" name="fb_sig_time" value="1252733930.265" /><input type="hidden" name="fb_sig_added" value="1" /><input type="hidden" name="fb_sig_profile_update_time" value="1251178770" /><input type="hidden" name="fb_sig_expires" value="1252738800" /><input type="hidden" name="fb_sig_user" value="100000164811549" /><input type="hidden" name="fb_sig_session_key" value="2.GJ1_wUgWsBaF_0EmahY_Zg__.3600.1252738800-100000164811549" /><input type="hidden" name="fb_sig_ext_perms" value="status_update,photo_upload,video_upload,create_note,share_item,auto_pu blish_short_feed,publish_stream,auto_publish_recent_activity" /><input type="hidden" name="fb_sig_api_key" value="63eade489b31633f81a5cd776197cc65" /><input type="hidden" name="fb_sig_app_id" value="10979261223" /><input type="hidden" name="fb_sig" value="ec2af2d2abe9c2155b89b000b1f18e9b" /><input type="hidden" name="ajax" value="1" /><input type="hidden" name="xw_user_name" value="[["John","Smith"]]" /> <table><tr>
<td>Amount: <input name="amount" type="text" value="71405413" style="width: 140px;" /></td>
<td><span class="sexy_button"><input type="submit" class="sexy_cash" name="do" value="Deposit" /></span></td>
</tr></table></form>
kassyopeia 09-12-2009, 12:10 AM The return type of document.all depends on how many elements match the criteria. It can be empty, for zero matches, an element, for one match, or a collection, for more than one match. This fact makes it a bit annoying to work with. One really ought to do a typecheck each time, rather than predicting the return type beforehand. Sample implementation (in javascript, I hope that's not a problem):
<html>
<head></head>
<body>
<input type="button" id="id1" name="name1" value="Button 1" onclick="alert (this.id + ' clicked')" />
<input type="button" id="id2" name="name1" value="Button 2" onclick="alert (this.id + ' clicked')" />
<input type="button" id="id3" name="name2" value="Button 3" onclick="alert (this.id + ' clicked')" />
<script>
clickAll("name1");
clickAll("name2");
clickAll("name3");
function clickAll(filter) {
var matches = document.all(filter);
if (matches == null) {
alert (filter + ": no matches");
} else if (matches.length == undefined) {
alert (filter + ": single match");
matches.click();
} else {
alert (filter + ": " + matches.length + " matches");
for (var i = 0; i < matches.length; ++i ) {
matches[i].click();
};
};
};
</script>
</body>
</html>
kassyopeia 09-12-2009, 12:25 AM Based on the HTML excerpt, calling Submit on the container form(s) should do fine, as the buttons have no secondary effects (onclick handlers or the like). And since the forms have ids, this is very straightforward.
'either one or both, as appropriate
document.getElementById("app10979261223_bank_withdraw").Submit
document.getElementById("app10979261223_bank_deposit").Submit
Cerian Knight 09-12-2009, 12:50 AM The code in the first example I linked worked fine for me with some minor modification:
Private Sub Form_Load()
WebBrowser1.Navigate ("file://C:\test.html")
End Sub
Private Sub WebBrowser1_DocumentComplete(ByVal pDisp As Object, URL As Variant)
Dim Item As Variant
Dim strValue As String
Dim I As Long
For Each Item In WebBrowser1.Document.All
I = I + 1
strValue = ""
On Error Resume Next
strValue = Item.Name & Item.Value
On Error GoTo 0
If strValue = "doWithdraw" Then
strValue = ""
Item.Click
End If
Next
End Sub
If getElementById works as kas describes for your code... that is very straightforward to implement. I wasn't aware multiple matches on All return a collection... that is too simple!
kassyopeia 09-12-2009, 01:20 AM I wasn't aware multiple matches on All return a collection... that is too simple!
I think it's not a plain-vanilla collection in VB, but a dedicated interface like (I)HTMLElementCollection. But it behaves like a collection for all intents and purposes, with some extra functionality added.
In general terms, it is preferrable to use document.getElementsByTagName and document.GetElementById rather than document.all, because the former are part of the W3C HTML DOM specs (http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document) and work across all browsers and languages, while the latter is a Microsoft invention from pre-DOM days, and basically deprecated.
protootorp 09-12-2009, 09:52 AM Thank you guys very much it works now. One question for Cerian, How does the DoWithdraw work? I don't find anywhere it says that in the HTML....
Just trying to understand why this code works so if another problem arises maybe i'll be able to figure it out.
once again thanks for the help it's truly appreciated.
kassyopeia 09-12-2009, 11:04 AM <input type="submit" class="sexy_cash" name="do" value="Withdraw" />
strValue = Item.Name & Item.Value
If strValue = "doWithdraw" Then
protootorp 09-12-2009, 11:45 AM ahhh, I feel silly. All this seems simple now.
I don't know why I couldn't even put item.name & item.value together to get doWithdraw. haha, sorry.
Well, I should say I will never come across a problem like this again, but I'm sure I will.
Last and final(hopefully), Thanks.
|