Mithrandir

Click a button in a webpage

5 posts in this topic

#1 ·  Posted (edited)

Hi, I'm trying to click a "button" -I name it like this because I'm quite new working with IE and autoit,although I know how to fill webforms- in a webpage. The button says "YES (let them know)". I used DebugBar and IE Builder to gather the data.

Here is the info from DebugBar (I used the aim to point to the button and get the section of the source code):

<A onmouseup="fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_yesno('yes','public');},17091798008],new fbjs_event(event));" class="sprite-btn btn-yltk" id=app17091798008_btn_yltk style="DISPLAY: block; COLOR: black; TEXT-DECORATION: none" onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return false;},17091798008],new fbjs_event(event));return true;" href="#" target=_blank fbcontext="3e114efabcd3"><DIV style="FONT-WEIGHT: bold; PADDING-TOP: 5px"><SPAN style="FONT-SIZE: 18px">YES</SPAN><BR>(Let Them Know)</DIV></A>

and here it's the info from IE Builder from HTML ELEMENTS and ANCHOR TAGS (I didn't look in FORMS because I know it isn't a form, I think from the code that it's in a table)

Object Type DispHTMLElementCollection 
Object Count  1613 

Characteristics of all HTML Elements on page


HTML ELEMENTS

Index       TAG ID              EXTRA INFORMATION

1085        A       app17091798008_btn_yltk     Link Text: YES (Let Them Know)
                            href: http://apps.facebook.com/areyouinterested/?ref=bm#

Object Type DispHTMLElementCollection 
Object Count  221 

Characteristics of all 'a' Links

ANCHOR TAGS

index          TAG      ID                              EXTRA INFORMATION
161         A       app17091798008_btn_yltk     Link Text: YES (Let Them Know)
                            href: http://apps.facebook.com/areyouinterested/?ref=bm#

I tried this code but it didn't click the button:

#include <IE.au3>
$oIE = _IECreate ("http://www.facebook.com/home.php")
$oForm = _IEFormGetCollection ($oIE, 0)
$oUsername = _IEFormElementGetCollection ($oForm, 7)
$oPassword = _IEFormElementGetCollection ($oForm, 8)
_IEFormElementSetValue ($oUsername, "Username")
_IEFormElementSetValue ($oPassword, "Password")
_IEFormSubmit ($oForm)
_IENavigate ($oIE, "http://apps.facebook.com/areyouinterested/?ref=bm")
$oButton = _IEGetObjById ($oIE, "app17091798008_btn_yltk")
_IEAction ($oButton, "click")

I also tried this:

#include <IE.au3>
$oIE = _IECreate ("http://www.facebook.com/home.php")
$oForm = _IEFormGetCollection ($oIE, 0)
$oUsername = _IEFormElementGetCollection ($oForm, 7)
$oPassword = _IEFormElementGetCollection ($oForm, 8)
_IEFormElementSetValue ($oUsername, "Username")
_IEFormElementSetValue ($oPassword, "Password")
_IEFormSubmit ($oForm)
_IENavigate ($oIE, "http://apps.facebook.com/areyouinterested/?ref=bm")
$oButton = _IELinkClickByIndex ($oIE, 161)
_IEAction ($oButton, "click")

And I received this error:

--> IE.au3 V2.4-0 Error from function _IEAction, $_IEStatus_InvalidDataType
+>22:45:34 AutoIT3.exe ended.rc:0
+>22:45:35 AutoIt3Wrapper Finished
>Exit code: 0    Time: 40.163

I used _IEGetObjById because in the example from the help file it uses it to get a reference to a DIV element:

; *******************************************************
; Example 1 - Open a browser to the basic example, get an object reference
;               to the DIV element with the ID "line1". Display the innerText
;               of this element to the console.
; *******************************************************
;
#include <IE.au3>
$oIE = _IE_Example ("basic")
$oDiv = _IEGetObjById ($oIE, "line1")
ConsoleWrite(_IEPropertyGet($oDiv, "innertext") & @CR)

and the button is inside a DIV part of the code:

<DIV class=ayi id=app17091798008_browse_content_area style="DISPLAY: block; TEXT-ALIGN: center" fbcontext="3e114efabcd3" fbjs_instance="18"><TABLE width="100%">
<TBODY>
<TR>
<TD style="WIDTH: 110px"></TD>
<TD>
<DIV style="FONT-WEIGHT: bold; FONT-SIZE: 20px; MARGIN: 5px; COLOR: #c40000; FONT-FAMILY: arial; TEXT-ALIGN: center">Are You Interested?</DIV></TD>
<TD style="WIDTH: 110px"></TD></TR>
<TR>
<TD></TD>
<TD>
<TABLE align=center>
<TBODY>
<TR>
<TD><A onmouseup="fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_yesno('yes','private');},17091798008],new fbjs_event(event));" class="sprite-btn btn-ya" id=app17091798008_btn_ya style="DISPLAY: block; COLOR: black; TEXT-DECORATION: none" onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return false;},17091798008],new fbjs_event(event));return true;" href="#" target=_blank fbcontext="3e114efabcd3">
<DIV style="FONT-WEIGHT: bold; PADDING-TOP: 5px"><SPAN style="FONT-SIZE: 18px">YES</SPAN><BR>(Anonymous)</DIV></A></TD>
<TD><A onmouseup="fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_yesno('yes','public');},17091798008],new fbjs_event(event));" class="sprite-btn btn-yltk" id=app17091798008_btn_yltk style="DISPLAY: block; COLOR: black; TEXT-DECORATION: none" onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return false;},17091798008],new fbjs_event(event));return true;" href="#" target=_blank fbcontext="3e114efabcd3">
<DIV style="FONT-WEIGHT: bold; PADDING-TOP: 5px"><SPAN style="FONT-SIZE: 18px">YES</SPAN><BR>(Let Them Know)</DIV></A></TD>
<TD><A onmouseup="fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_yesno('no','public');},17091798008],new fbjs_event(event));" class="sprite-btn btn-s" id=app17091798008_btn_s style="DISPLAY: block; COLOR: black; TEXT-DECORATION: none" onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return false;},17091798008],new fbjs_event(event));return true;" href="#" target=_blank fbcontext="3e114efabcd3">
<DIV style="FONT-WEIGHT: bold; PADDING-TOP: 12px"><SPAN style="FONT-SIZE: 18px">SKIP</SPAN></DIV></A></TD></TR></TBODY></TABLE></TD>
<TD></TD></TR></TBODY></TABLE>
<TABLE cellPadding=10 align=center>
<TBODY>
<TR>
<TD vAlign=top width=200>
<DIV class=about_me_div style="DISPLAY: block; OVERFLOW: hidden; WIDTH: 200px; TEXT-ALIGN: right">
<DIV id=app17091798008_p_on style="DISPLAY: block; FONT-WEIGHT: bold; FONT-SIZE: 16px; COLOR: #ff0000" fbcontext="3e114efabcd3" fbjs_instance="10">Online Now!</DIV><B><SPAN style="FONT-SIZE: 16px"><SPAN id=app17091798008_p_fbml_n fbcontext="3e114efabcd3" fbjs_instance="1">Rahim</SPAN>&nbsp; <SPAN id=app17091798008_p_ag fbcontext="3e114efabcd3" fbjs_instance="2">26</SPAN><SPAN id=app17091798008_p_g fbcontext="3e114efabcd3" fbjs_instance="3">, M</SPAN><BR><SPAN id=app17091798008_p_ci fbcontext="3e114efabcd3" fbjs_instance="4">Dallas</SPAN><BR><SPAN id=app17091798008_p_st fbcontext="3e114efabcd3" fbjs_instance="5">TX</SPAN><SPAN id=app17091798008_p_co fbcontext="3e114efabcd3" fbjs_instance="6"> / US</SPAN></SPAN><BR><BR><A id=app17091798008_p_fpl onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_browse_full_profile($FBJS.ref(this));},17091798008],new fbjs_event(event));return true;" href="#" target=_blank fbcontext="3e114efabcd3">[View More Pics And Profile]</A> <BR><BR><A id=app17091798008_p_sm onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_browse_send_message($FBJS.ref(this));},17091798008],new fbjs_event(event));return true;" href="#" target=_blank fbcontext="3e114efabcd3">[Send Gift/Message]</A> <BR><BR>About Me </B><BR><SPAN id=app17091798008_p_am fbcontext="3e114efabcd3" fbjs_instance="7"><SPAN fbjs_instance="8">Click YES on me!</SPAN></SPAN></DIV></TD>
<TD class=centered vAlign=top width=210>
<DIV style="OVERFLOW: hidden; WIDTH: 210px"><SPAN id=app17091798008_p_fbml_ni fbcontext="3e114efabcd3" fbjs_instance="0"><IMG title="" alt="" src="http://profile.ak.fbcdn.net/v224/1174/113/n100000119166733_5751.jpg" uid="100000119166733" linked="no" size="n"></SPAN></DIV></TD>
<TD class=centered vAlign=top width=105>
<DIV style="MARGIN-TOP: 15px">Upcoming<BR>
<DIV style="OVERFLOW: hidden; WIDTH: 105px"><SPAN id=app17091798008_p_fbml_nis fbcontext="3e114efabcd3" fbjs_instance="16"><IMG title="" alt="" src="http://profile.ak.fbcdn.net/v22939/1857/124/n100000197378426_9000.jpg" width=100 uid="100000197378426" linked="no" size="n"></SPAN></DIV></DIV></TD></TR></TBODY></TABLE><BR><BR><FONT size=1><A id=app17091798008_p_ru onclick="(new Image()).src = '/ajax/ct.php?app_id=17091798008&amp;action_type=3&amp;post_form_id=7cda7e16b55446920bb8a2c088668a25&amp;position=3&amp;' + Math.random();fbjs_sandbox.instances.a17091798008.bootstrap();return fbjs_dom.eventHandler.call([fbjs_dom.get_instance(this,17091798008),function(a17091798008_event) {return a17091798008_browse_ru();},17091798008],new fbjs_event(event));return true;" href="#" fbcontext="3e114efabcd3">[Report]</A></FONT> </DIV>

Any ideas to solve this? I'm stucked :mellow: Thanks for your help!

PS:@Moderators: I don't know what happened that I posted twice this thread. Anyway, this is the thread I want to keep because the other is incomplete. I guess it was a preview I made. Sorry for the inconvenience.

Edited by Mithrandir

Share this post


Link to post
Share on other sites



Nearly all anchors rely on just an onclick event to activate them. You'll see on the tag for this one that it also uses onmouseup. You'll likely need to code the events and actions on this one manually.

From this code you used I think you have determined that it is link 161:

$oButton = _IELinkClickByIndex ($oIE, 161)

(btw, that function does not return an object, whish is why you got the error you did when you tried to use $oButton)

so, you could try:

$oButton = _IELinkGetCollection($oIE, 161)
$oButton.fireEvent("onmouseup")
$oButton.click

Dale


Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Hi All,

I need script to click on tab button in application. kindly help me on this.

PFB- Snippet

<div class="VNavLeaf VNavSelected VNavLevel2 arfid536870308 ardbnnav.RM.CreateSR" style="height: 25px; background-color: rgb(238, 243, 245);" ardbn="nav.RM.CreateSR" artype="NavBarItem" arid="536870308" navmode="0" parentid="536870339" type="vert" arwindowid="0">

Menu tab name : Create SR

 

 

Edited by Eddieedison

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Welcome to AutoIt and the forum!

This thread is > 5 years old. I suggest you open a new one and link to this one if necessary.
This way you will get much more replies ;)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now