Jump to content

How to Click Jquery button on IE


abiteric
 Share

Recommended Posts

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

@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 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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 3.3.14.2 X86 - SciTE 3.6.0WIN 8.1 X64 - Other Example Scripts

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...