Sign in to follow this  
Followers 0

How to Click Jquery button on IE

24 posts in this topic

#1 ·  Posted

Target : http://bible.l2play.com/test.asp

How do I click that by Autoit ? I don`t want catch pixel or move mouse to XXX,YYY and controlclick.

#AutoIt3Wrapper_run_debug_mode=Y
#include <IE.au3>

$oie = _IECreate("http://bible.l2play.com/test.asp",0,1,1,0)
$obutton = _IEGetObjById($oie,"Upload_btn")


;way1 : X
_IEAction($obutton,"focus")
MsgBox(0,"focus",@error)
_IEAction($obutton,"click")
MsgBox(0,"click",@error)

;way2 : X
_IELinkClickByText($oie,"Upload",0,1)
MsgBox(0,"_IELinkClickByText",@error)

;way3 : X
_IELinkClickByIndex($oie,0,1)
MsgBox(0,"_IELinkClickByIndex",@error)

My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909

Share this post


Link to post
Share on other sites



#2 ·  Posted

Add _IEErrorHandlerRegister() to your script and/or some other error checking to see if $obutton actually has a valid object reference in it. If it's buried inside one or more frames for instance there might be some more effort required.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

@abiteric

I have tried differents way, there is no errors but nothing happen ! Posted Image

If someone have an idea...

#include <IE.au3>

$oIE= _IECreate("http://bible.l2play.com/test.asp")
_IELoadWait($oIE)
$oDiv = _IEGetObjById ($oIE, "Upload_btn")
_IEAction($oDiv, "click")


#include <IE.au3>

$oIE = _IECreate ( "http://bible.l2play.com/test.asp" )
$oLinks = _IELinkGetCollection ( $oIE )
$iLinksCnt = @extended 
For $oLink In $oLinks
    If $oLink.innertext = 'Upload' Then
        ConsoleWrite ( $iLinksCnt & " Link : " & $oLink.href & " ID : " & $oLink.id & " Name : " & $olink.Name & " Text : " & $oLink.innertext & @LF )
        _IELinkClickByText ( $oLink, $oLink.innertext )
        ;_IELinkClickByIndex ( $oLink, 0 )
        ;_IEAction ( $oLink, "click" )
    EndIf
Next


#include <IE.au3>

$oIE = _IECreate ( "http://bible.l2play.com/test.asp" )
$oElements = _IETagNameAllGetCollection ($oIE)
For $oElement In $oElements
    ConsoleWrite ( "Tagname : " & $oElement.tagname & @Crlf )
    ConsoleWrite ( "innerText : " & $oElement.innerText & @Crlf )
    ;If $oElement.tagname = "A" Then _IEAction ( $oElement, "click" )
    If $oElement.innerText = "Upload" Then _IEAction ( $oElement, "click" )
Next
Edited by wakillon

AutoIt Version : 3.3.14.0 SciTE 3.5.4 WIN8.1 X64

Share this post


Link to post
Share on other sites

#4 ·  Posted

Let's try this again... what is the DOM path to the element you want to click on? Look at it with DebugBar or another DOM Inspector.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

@PsaltyDS

DOM Path of UPLOAD Button : HTML, BODY, A href=javascript:void(0)

There is no form, frame or name and no "onclick" action

it's misery ! Posted Image

Edited by wakillon

AutoIt Version : 3.3.14.0 SciTE 3.5.4 WIN8.1 X64

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

__IEImgClick() works like a charm for me ;)

***edit***

sorry, i meant normally. the link wasn't there to try for this page when i'd originally posted. playing with the actual example now...

Edited by cameronsdad

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#7 ·  Posted

@cameronsdad

The img was include in a CSS style

The button click by hand, will open a file dialoag, but can`t click by autoit ;)

jquery lock the "click" ?


My website about Y-mate 網拍輔助程式 : http://www.L2play.comMy Blog ( Tranditional Chinese ) 開發小組的部落格 : http://tw.myblog.yahoo.com/play19990909

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Nothing works !

#include <IE.au3>

$oIE = _IECreate ( "http://bible.l2play.com/test.asp" )
_IELoadWait($oIE)
_IEImgClick ( $oIE, "http://www.aircamel.com.tw/images/universal/button_bg.png" )

#include <IE.au3>

$oIE = _IECreate ( "http://bible.l2play.com/test.asp" )
_IELoadWait($oIE)
$oDiv = _IEGetObjById ($oIE, "Upload_btn")
_IEImgClick ( $oDiv, "Upload", "name" )

#include <IE.au3>

$oIE = _IECreate ( "http://bible.l2play.com/test.asp" )
_IELoadWait($oIE)
_IEImgClick ( $oIE, "Upload", "name" )


#include <IE.au3>

$oIE = _IECreate ( )
_IENavigate ( $oIE, "http://bible.l2play.com/test.asp" )
$oElements = _IETagNameAllGetCollection ($oIE)
For $oElement In $oElements
    If StringInStr ( $oElement.innerText, 'Upload' ) <> 0 Then 
        ConsoleWrite ( "Element Tagname : " & $oElement.tagname & " innerText:" & $oElement.innerText & ':' & @LF )
        _IEAction ( $oElement, "click" )
    EndIf
Next
Edited by wakillon

AutoIt Version : 3.3.14.0 SciTE 3.5.4 WIN8.1 X64

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

There's some confusion here because there is no image. Here's the HTML:

<html>    
<head>   
<style>
.button {
    BORDER-RIGHT: 1px solid #999;
    WIDTH: auto;
    FONT-SIZE: 12;
    WORD-WRAP: break-word;
    MARGIN-TOP: 0px;
    CURSOR: pointer;
    OVERFLOW: visible;
    WHITE-SPACE: nowrap;
    HEIGHT: auto;
    TEXT-DECORATION: none;
    BORDER-LEFT: 1px solid #999;
    BORDER-COLLAPSE: collapse;
    VERTICAL-ALIGN: baseline;
    OUTLINE-STYLE: none;
    PADDING-TOP: 4px;
    DISPLAY: inline-block;
    POSITION: relative;
    BORDER-TOP: 1px solid #999;
    BORDER-BOTTOM: 1px solid #999;
    BACKGROUND: #ffffff url("http://www.aircamel.com.tw/images/universal/button_bg.png") repeat-x;
    OUTLINE-COLOR: invert;
    FONT-FAMILY: Arial;
    BACKGROUND-COLOR: #ffffff;
    LINE-HEIGHT: 18px;
    PADDING-RIGHT: 11px;
    OUTLINE-WIDTH: 0px;
    PADDING-LEFT: 11px;
    MIN-HEIGHT: auto;
    FONT-WEIGHT: 700;
    COLOR: #333333;
    MARGIN: 0px;
    PADDING-BOTTOM: 3px;    
    }
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
  <script type=text/javascript src="http://www.aircamel.com.tw/js/jquery.js"></SCRIPT>
  <script type=text/javascript src="http://www.aircamel.com.tw/js/ajaxupload.js"></SCRIPT>
  <script type=text/javascript src="http://www.aircamel.com.tw/js/upload_pic.js"></SCRIPT>
  <script type=text/javascript src="http://www.aircamel.com.tw/js/blockUI.js"></SCRIPT>
</head>    
<Body>
<A id=Upload_btn class="button          " href="javascript:void(0)">Upload</A>    
</body>
</Html>

There is a button type link called "Upload_btn". Just because you loaded a .png file as background for the button does not change it to an IMG tag. You need to treat the button as an ordinary link, not as an IMG:

_IELinkClickByText($oIE, "Upload")

; -- or --

$oElement = _IEGetObjById ($oIE, "Upload_btn")
_IEAction( $oElement, "Click")

; -- or --

$oElement = _IEGetObjById ($oIE, "Upload_btn")
_IEAction ($oElement, "focus")
$hwnd = _IEPropertyGet($oIE, "hwnd")
ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#10 ·  Posted

I tried _IEImgClick() because cameronsdad said it works

but I allready try for Link ( see my first post ).

_IELinkClickByText ( $oLink, $oLink.innertext )

_IELinkClickByIndex ( $oLink, 0 )

_IEAction ( $oLink, "click" )

I find 3 Tags "A", "Body", "Html" but _IEAction doesn't work... ( third post )


AutoIt Version : 3.3.14.0 SciTE 3.5.4 WIN8.1 X64

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Did you try the "focus" then ControlSend() method (last example in my previous post)?

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#12 ·  Posted

Did you try the "focus" then ControlSend() method (last example in my previous post)?

;)

Absolutly, but no result Posted Image

I verified that ie infos ( with autoi windo info ) are the same for my ie version and it's the case.

So...


AutoIt Version : 3.3.14.0 SciTE 3.5.4 WIN8.1 X64

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

No, the link is being clicked, but those javascripts from whatever "aircamel.com.tw" is don't respond. You'll have to take that up with those blokes. This works fine:

#include <IE.au3>

$sHTML = '<html><head><style>.button {' & @CRLF & _
        'BORDER-RIGHT: 1px solid #999;' & @CRLF & _
        'WIDTH: auto;' & @CRLF & _
        'FONT-SIZE: 12;' & @CRLF & _
        'WORD-WRAP: break-word;' & @CRLF & _
        'MARGIN-TOP: 0px;' & @CRLF & _
        'CURSOR: pointer;' & @CRLF & _
        'OVERFLOW: visible;' & @CRLF & _
        'WHITE-SPACE: nowrap;' & @CRLF & _
        'HEIGHT: auto;' & @CRLF & _
        'TEXT-DECORATION: none;' & @CRLF & _
        'BORDER-LEFT: 1px solid #999;' & @CRLF & _
        'BORDER-COLLAPSE: collapse;' & @CRLF & _
        'VERTICAL-ALIGN: baseline;' & @CRLF & _
        'OUTLINE-STYLE: none;' & @CRLF & _
        'PADDING-TOP: 4px;' & @CRLF & _
        'DISPLAY: inline-block;' & @CRLF & _
        'POSITION: relative;' & @CRLF & _
        'BORDER-TOP: 1px solid #999;' & @CRLF & _
        'BORDER-BOTTOM: 1px solid #999;' & @CRLF & _
        'OUTLINE-COLOR: invert;' & @CRLF & _
        'FONT-FAMILY: Arial;' & @CRLF & _
        'BACKGROUND-COLOR: #ffffff;' & @CRLF & _
        'LINE-HEIGHT: 18px;' & @CRLF & _
        'PADDING-RIGHT: 11px;' & @CRLF & _
        'OUTLINE-WIDTH: 0px;' & @CRLF & _
        'PADDING-LEFT: 11px;' & @CRLF & _
        'MIN-HEIGHT: auto;' & @CRLF & _
        'FONT-WEIGHT: 700;' & @CRLF & _
        'COLOR: #333333;' & @CRLF & _
        'MARGIN: 0px;' & @CRLF & _
        'PADDING-BOTTOM: 3px};' & @CRLF & _
        '</style>' & @CRLF & _
        '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />  ' & @CRLF & _
        '</head><Body>' & @CRLF & _
        '<A id=Upload_btn class="button" href="javascript:alert(''Clicky'')">Upload</A>' & @CRLF & _
        '</body></Html>'

$oIE = _IECreate()
_IEDocWriteHTML($oIE, $sHTML)
_IEAction($oIE, "refresh")

Sleep(2000)

_IELinkClickByText($oIE, "Upload")

And by the way, the <meta> was wrong because it was missing its terminator.

;)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#14 ·  Posted

Ok !

so if i understand well it's the javascript:void(0) who block the click or the action after the click ?

I have googleled yesterday for "javascript:void(0)" but i didn't found any understanding answer !

How does the javascript does the difference between real click and false ? Posted Image


AutoIt Version : 3.3.14.0 SciTE 3.5.4 WIN8.1 X64

Share this post


Link to post
Share on other sites

#15 ·  Posted

No, javascript:void(0) is NoOp to keep the page from navigating anywhere else while the onclick scripts are run.

In this case the problem is in the .js scripts in the head section, brought from "aircamel.com.tw". They must be broken or intentionally blocking. Note one of them is called "blockUI.js". I assume web masters have techniques available to at least make botting their page difficult. Maybe they don't want you botting that site.

;)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#16 ·  Posted (edited)

OK, I've taken a look at this and will admit that it is still rather mysterious.

There are two clandestine things happening on this page. First, there is a reliance on the mouse being positioned over the element. There is some event being captured when this happens that is actually triggering the second clandestine occurance... the dynamic creation of an INPUT TYPE=FILE element.

So, the following sequence works, but your script will hang waiting for the file dialog to be dismissed.

#include <IE.au3>

$oIE = _IECreate('http://bible.l2play.com/test.asp',1)

; Position mouse over link
$oElement = _IEGetObjById($oIE, "Upload_btn")
$iScreenX = _IEPropertyGet($oElement, "screenx")
$iScreenY = _IEPropertyGet($oElement, "screeny")
$iWidth = _IEPropertyGet($oElement, "width")
$iHeight = _IEPropertyGet($oElement, "height")
MouseMove($iScreenX + $iWidth/2, $iScreenY + $iHeight/2)

; input type=file element created dynamically
$oInput = _IETagnameGetCollection($oIE, "input", 0)
_IEAction($oInput, "click")

ConsoleWrite("I won't display until the file dialog is closed..." & @CRLF)

Exit

Dale

Edited by DaleHohm

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

#17 ·  Posted

Update, aleternative.

OK, with this solution you don't have to even know about the dynamic INPUT element and your script will continue after the file dialog is displayed so that you can interact with it via script:

#include <IE.au3>

$oIE = _IECreate('http://bible.l2play.com/test.asp',1)

; Position mouse over link
$oElement = _IEGetObjById($oIE, "Upload_btn")
$iScreenX = _IEPropertyGet($oElement, "screenx")
$iScreenY = _IEPropertyGet($oElement, "screeny")
$iBrowserX = _IEPropertyGet($oElement, "browserx")
$iBrowserY = _IEPropertyGet($oElement, "browsery")
$iWidth = _IEPropertyGet($oElement, "width")
$iHeight = _IEPropertyGet($oElement, "height")
MouseMove($iScreenX + $iWidth/2, $iScreenY + $iHeight/2)

ControlClick(_IEPropertyGet($oIE, "hwnd"), "", "", "left", 1, $iBrowserX + $iWidth/2, $iBrowserY + $iHeight/2)

Exit

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

#18 ·  Posted

Ok !

so if i understand well it's the javascript:void(0) who block the click or the action after the click ?

I have googleled yesterday for "javascript:void(0)" but i didn't found any understanding answer !

How does the javascript does the difference between real click and false ? Posted Image

here's another approach for you that works on my side for your example... use

$oIE = _IECreate("http://bible.l2play.com/test.asp")
$btn = _IEGetObjById($oIE,"Upload_btn")
to get a reference to the button, THEN, you can use mouseclick() to click at the location using $btn.style.Left+10 and $btn.style.Top+10 after doing any necessary offset for window position and then toolbars etc. (in your example it goes at 0,0 so figuring the offset for window and and titlebar should be easy

1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

OK, I'm done now... it is the onmouseover event that is being used to trigger the dynamic HTML creation. No need to move the mouse on the screen now...

#include <IE.au3>

$oIE = _IECreate('http://bible.l2play.com/test.asp',1)

; trigger dynamic INPUT TYPE=FILE element creation with onmouseover
$oElement = _IEGetObjById($oIE, "Upload_btn")
$oElement.fireEvent("onmouseover")

; The next two lines will bring up the file dialog, but hang script until it is dismissed
;$oInput = _IETagnameGetCollection($oIE, "input", 0)
;_IEAction($oInput, "click")

; Alternate method that can be performed on a hidden browser and will not pause script
$iBrowserX = _IEPropertyGet($oElement, "browserx")
$iBrowserY = _IEPropertyGet($oElement, "browsery")
$iWidth = _IEPropertyGet($oElement, "width")
$iHeight = _IEPropertyGet($oElement, "height")
ControlClick(_IEPropertyGet($oIE, "hwnd"), "", "", "left", 1, $iBrowserX + $iWidth/2, $iBrowserY + $iHeight/2)

Exit

Dale

Edited by DaleHohm

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

#20 ·  Posted

very nice, didn't even think of going that route


1100111 00001011101111 00011101101111 00010111100100 00001111110100 00110111110010 00101101111001 0011100i didn't make up this form of encryption, but i like it.credit to the lvl 6 challenge on arcanum.co.nz

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
Sign in to follow this  
Followers 0