Jump to content

_IE how to click item by Class?


Recommended Posts

Get the collection of all links with _IELinkGetCollection() then walk through them with a For/In/Next loop to find the one you want:

$oFound = ""
$colLinks = _IELinkGetCollection($oIE)
For $oLink In $colLinks
    If $oLink.className & "" = "signIn" Then
        $oFound = $oLink
        ExitLoop
    EndIf
Next
If IsObj($oFound) Then 
    MsgBox(64, "Success", "Found it!")
Else
    MsgBox(16, "Failed", "Not found.")
EndIf

:blink:

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

  • 2 years later...

Hi i have a similar issue, i tried your code but it does not seem to work for me? always comes back "Failed, Not found"

<button class="action af_commandButton" onclick="submitForm('ManageUsers',1,{source:'_id106:_id133'});return false;" type="button">

 

$oFound = ""
$colLinks = _IELinkGetCollection($oIE)
For $oLink In $colLinks
    If $oLink.className & "" = "action af_commandButton" Then
  $oFound = $oLink
  ExitLoop
 EndIf
Next
If IsObj($oFound) Then
 MsgBox(64, "Success", "Found it!")
Else
 MsgBox(16, "Failed", "Not found.")
EndIf
Link to comment
Share on other sites

Thanks for your help, it seems to be working it now comes back saying "Found" howveer i still can't click it, have i done this right? thanks.

$oFound = ""
Local $oBtns = _IETagNameGetCollection($oIE, "button")
For $oBtn In $oBtns
    If String($oBtn.classname) = "action af_commandButton" Then
     $oFound = $oBtn
   EndIf
Next
If IsObj($oFound) Then
 _IEAction ($oFound, "click")
 MsgBox(16, "Success", "Password23 with a captial P (Roles have been set)")
Else
 MsgBox(16, "Failed", "Not found.")
EndIf
endfunc
Edited by Annonyreeder
Link to comment
Share on other sites

I'm not sure this will work or not, but try to get the ID of the $oFound item and save it as $obtn, and then click the $obtn:

Local $oFound = ""
Local $oBtns = _IETagNameGetCollection($oIE, "button")

For $oBtn In $oBtns
    If String($oBtn.classname) = "action af_commandButton" Then
     $oFound = $oBtn
   EndIf
Next

If IsObj($oFound) Then
    Local $obtn = _IEFormElementGetObjByName($o_IE, $oFound.id) ; Get ID of the button    
    _IEAction ($obtn, "click")
    MsgBox(16, "Success", "Password23 with a captial P (Roles have been set)")
Else
    MsgBox(16, "Failed", "Not found.")
EndIf
Link to comment
Share on other sites

If you are getting Success, it is actually performing a click event on the element.  If it is not producing the desired results, it may be that more than a simple click is required.  When you click with the mouse, you actually generate events onmousedown, onmouseup, click. So, you can try this:

$oFound.fireEvent("onmousedown")
$oFound.fireEvent("onmouseup")
_IEAction($oFound, "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

Link to comment
Share on other sites

  • 4 weeks later...

Hey i just found this post from awhile ago, and im still having the same problem, however the reason im getting the issue is because there are several buttons all with the exact same class + type the only part thta differs is the "Onclick"

 
<BUTTON class="action af_commandButton" onclick="submitForm('ManageUsers',1,{source:'_id106:_id133'});return false;" type=button>Assign</BUTTON>
 
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...