Página 1 de 1

Clickear un botón en una página web

Publicado: 16 Feb 2010, 02:32
por Mithrandir
Hola, estoy tratando de cliquear un "botón" (lo llamo así porque soy bastante nuevo con IE pero sé llenar webforms) en una página web. El botón dice "YES (let them know)". Usé Debug Bar e IE Builder para obtener información de la página.

Acá está la información del Debug Bar (usé lo de arrastrar el objetivo hasta el botón para obtener la región del código):

Código: Seleccionar todo

<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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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>
y acá está la información del IE Builder de HTML ELEMENTS y ANCHOR TAGS (no me fijé en FORMS porque sé que no es un form, de observar el código me parece que está en una tabla):

Código: Seleccionar todo

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#


Código: Seleccionar todo

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#


Probé con este código pero no clickeó el botón:

Código: Seleccionar todo

#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")
También probé esto:

Código: Seleccionar todo

#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")
Y recibí este error:

Código: Seleccionar todo

   
--> 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
Usé _IEGetObjById porque en el ejemplo de la ayuda lo usa para obtener una referencia a un elemento DIV:

Código: Seleccionar todo

; *******************************************************
; 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)
y el botón está dentro de la parte DIV del código:

Código: Seleccionar todo

<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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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>  <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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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&action_type=3&post_form_id=7cda7e16b55446920bb8a2c088668a25&position=3&' + 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>
¿Alguna idea sobre como resolver esto? Estoy trancado :smt009 ¡Gracias por la ayuda!

Re: Clickear un botón en una página web

Publicado: 16 Feb 2010, 03:32
por Nahuel
Mi IE es muy viejo y se clava cuando intento entrar al sitio :smt003

Has probado con _IELinkClickByText?

Re: Clickear un botón en una página web

Publicado: 16 Feb 2010, 03:47
por Mithrandir
Nahuel escribió:Mi IE es muy viejo y se clava cuando intento entrar al sitio :smt003

Has probado con _IELinkClickByText?
¡Gracias por la respuesta!

Probé esto:

Código: Seleccionar todo

#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")
For $i = 1 to 5
_IELinkClickByText ($oIE, "YES (Let Them Know)")
Sleep (5000)
Next
Y me tira estos errores:

Código: Seleccionar todo

--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
--> IE.au3 V2.4-0 Warning from function _IELinkClickByText, $_IEStatus_NoMatch
Parece que no se lo puede tratar como un link, sin embargo aparece en ANCHOR TAGS del IE Builder :smt017

Re: Clickear un botón en una página web

Publicado: 16 Feb 2010, 04:14
por Nahuel
Bueno pues has puesto mal el texto.
Es:

Código: Seleccionar todo

Yes
(Let them know)
no:

Código: Seleccionar todo

Yes (Let them know)
Con este pequeño script podés obtener los textos de los links:

Código: Seleccionar todo

$oIE =  _IECreate("url")
$oLinks = _IELinkGetCollection ($oIE)
$iNumLinks = @extended
MsgBox(0, "Link Info", $iNumLinks & " links found")
For $oLink In $oLinks
    MsgBox(0, "Link Info", $oLink.innerText)
Next
Esto me funcionó a la perfección (al menos para mi):

Código: Seleccionar todo

#include <IE.au3>

$oIE =  _IECreate("url")
_IELinkClickByText($oIE,"YES" & @CRLF & "(Let Them Know)")
A pesar que te he ayudado, desapruebo totalmente el uso de bots para estas cosas. Confío que estás bienintencionado.

Re: Clickear un botón en una página web

Publicado: 16 Feb 2010, 07:13
por Mithrandir
Quedate tranquilo no pienso hacer ningún bot, es que me aburrí de los forms y empezé a ver otras cosas :smt001 y facebook tiene muchos botones y cosas raras :smt020 ¿Sabés algún lugar donde se pueda probar estas cosas? (Para practicar forms tengo una parte de tests en un foro) y de algún manual o guía para cosas como forms que tengan input type = hidden? . Bueno, para no desviarme de tema probé el código

Código: Seleccionar todo

#include <IE.au3>
$oIE = _IECreate ("http://apps.facebook.com/areyouinterested/?ref=bm")
For $i = 1 To 5
_IELinkClickByText($oIE,"YES" & @CRLF & "(Let Them Know)")
Sleep (5000)
Next
Y sigue sin clickear aunque no me da ningún error :smt120

También probé esto:

Código: Seleccionar todo

#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)
$oIE2 = _IENavigate ($oIE, "http://apps.facebook.com/areyouinterested/?ref=bm")
For $i = 1 to 5
_IELinkClickByText($oIE2,"YES" & @CRLF & "(Let Them Know)")
_IELoadWait ($oIE)
Sleep (5000)
Next
Y me tira estos errores (me pasa lo mismo si pongo un $oIE3 = IELoadWait ($oIE2) a continuación de $oIE2 y después _IELinkClickByText($oIE3,"YES" & @CRLF & "(Let Them Know)") )

Código: Seleccionar todo

--> IE.au3 V2.4-0 Error from function _IELinkClickByText, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IELinkClickByText, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IELinkClickByText, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IELinkClickByText, $_IEStatus_InvalidDataType
--> IE.au3 V2.4-0 Error from function _IELinkClickByText, $_IEStatus_InvalidDataType
¿A vos te funcionó el primer código? ¿Qué Internet Explorer tenés? Yo tengo el 7. Estaba pensando en posicionar el mouse encima del botón (link) y después mandar un click pero no estoy seguro de como hacerlo. Pienso hacerlo a partir de este ejemplo:

Código: Seleccionar todo

; *******************************************************
; Example 2 - Open a browser with the form example and get a reference to the form 
;               textarea element.  Get the coordinates and dimensions of the text area,
;               outline its shape with the mouse and come to rest in the center
; *******************************************************
;
$oIE = _IE_Example("form")

$oForm = _IEFormGetObjByName($oIE, "ExampleForm")
$oTextArea = _IEFormElementGetObjByName($oForm, "textareaExample")

; Get coordinates and dimensions of the textarea
$iScreenX = _IEPropertyGet($oTextArea, "screenx")
$iScreenY = _IEPropertyGet($oTextArea, "screeny")
$iBrowserX = _IEPropertyGet($oTextArea, "browserx")
$iBrowserY = _IEPropertyGet($oTextArea, "browserY")
$iWidth = _IEPropertyGet($oTextArea, "width")
$iHeight = _IEPropertyGet($oTextArea, "height")

; Outline the textarea with the mouse, come to rest in the center
MouseMove($iScreenX, $iScreenY)
MouseMove($iScreenX + $iWidth, $iScreenY)
MouseMove($iScreenX + $iWidth, $iScreenY + $iHeight)
MouseMove($iScreenX, $iScreenY + $iHeight)
MouseMove($iScreenX, $iScreenY)
MouseMove($iScreenX + $iWidth/2, $iScreenY + $iHeight/2)

Re: Clickear un botón en una página web

Publicado: 16 Feb 2010, 17:31
por Nahuel
No hay caso, intento entrar a esa aplicación y se me cuelga internet explorer. Tengo el 6... jeje.
Lo que hice fue copiar el código fuente que me has dado en un archivo html y probar de ahí. Aparentemente no es lo mismo, no sé por qué.

A ver esto:

Código: Seleccionar todo

#include <IE.au3>

$oIE =  _IECreate("C:\Documents and Settings\Yo\Escritorio\new 1.html")

$oLinks = _IELinkGetCollection ($oIE)
For $oLink In $oLinks
    If StringInStr($oLink.innerText,"let them know") Then _IEAction($oLink,"click")
Next
También funciona acá.

Otro código que también funciona y tal vez es más probable que te funcione a vos:

Código: Seleccionar todo

$oIE =  _IECreate("C:\Documents and Settings\Yo\Escritorio\new 1.html")
$hwnd = _IEPropertyGet($oIE, "hwnd")

$oLinks = _IELinkGetCollection ($oIE)
For $oLink In $oLinks
    If StringInStr($oLink.innerText,"let them know") Then
		_IEAction ($oLink, "focus")
		ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")
	EndIf
Next
Lo que hace es dar foco al elemento y luego enviar {ENTER} a IE. Incluso hasta puede verse como le da foco.

Re: Clickear un botón en una página web

Publicado: 16 Feb 2010, 21:23
por Chefito
Sí Nahuel, hay algunas cosas que en internet no se comportan igual que si se baja la página y la atacas :smt002 .
Parece ser que este enlace es un tanto rebelde y no se deja cliquear :smt012 . No pasa nada, le atacaremos por otro flanco :smt005 :smt016 .
He disparado el evento "onmouseup" de este objeto para que se ejecute lo que tiene.
Al final el código queda así.

Código: Seleccionar todo

#include <IE.au3>
$oIE=_IECreate("http://www.facebook.com/login.php");,0,0)
$oEmail=_IEGetObjById($oIE,"email")
If @error=0 Then $oEmail.value="correo"   ;aquí va el correo del usuario.
$opass=_IEGetObjById($oIE,"pass")
$opass.value="password"   ;aquí va la password del usuario.
$oForm=_IEFormGetObjByName($oIE,"login_form")
_IEFormSubmit($oForm)
_IENavigate ($oIE, "http://apps.facebook.com/areyouinterested/?ref=bm")
$link=_IEGetObjById($oIE,"app17091798008_btn_yltk")
$link.fireEvent('onmouseup')

Parece que funciona. Digo parece porque me ha mandado lo que quiera que mande al principio, poniendome esa ventana emergente que te dice que ha sido enviado. Pero después de varias pruebas, me pasaba las fotos y no me salía la ventana esa que me lo confirmaba. Aunque en este caso, le daba al botón manualmente y se comportaba igual....no me salía esa ventana :smt017 .
Puede que haya un límite de envíos o que se yo......puede que sea de mi ordenador, etc.

Saludos.

Re: Clickear un botón en una página web

Publicado: 17 Feb 2010, 04:45
por Nahuel
Ahhh, muchas gracias por la corrección.