Jump to content

Multiple buttons with no id - (Moved)


Pagi
 Share

Recommended Posts

Hello guys, I am still learning AutoIt, especially button clicks and I´ve got this problem. I dont´know how can I click the button without id, when there are other buttons with same class. Mb some index or something like that. I tried this method and it returns me error 

Func att()
$oButtons = _IETagNameGetCollection ($oIE, "button") ; 
For $oButton In $oButtons
If $oButton.class = "awesome-button" Then
_IEAction ($oButton, "click")
ExitLoop
EndIf
Next
   EndFunc
<button class="awesome-button " onclick="click(null, '0', 1, 0, '')">Click</button>
<button class="awesome-button " onclick="click(null, '0', 2, 0, '')">Click</button>
<button class="awesome-button " onclick="click(null, '0', 3, 0, '')">Click</button>
<button class="awesome-button " onclick="click(null, '0', 4, 0, '')">Click</button>

Each button has the same text. The only different is between that numbers (I guess it´s some kind of index or something like that)

Any advices?

Link to comment
Share on other sites

  • Developers

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions. If it's super geeky and you don't know where to put it - it's probably here.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

Seems you really have issues reading this warnings as this did happen before..... 

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

4 hours ago, Pagi said:

.... I tried this method and it returns me error ...

what error did you get? (:whisper: usually the error returned is useful to identify the problem.... )
Since you are working within a function scope, have you declared the $oIE variable as Global in the main script scope..?
Also, have a look the third parameter of the _IETagNameGetCollection function, using that parameter you can select just one of the many buttons returned...

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

@Chimp  "C:\Program Files (x86)\AutoIt3\Include\IE.au3" (1811) : ==> The requested action with this object has failed.:
Return SetError($_IESTATUS_Success, $oTemp.GetElementsByTagName($sTagName).length, $oTemp.GetElementsByTagName($sTagName))
Return SetError($_IESTATUS_Success, $oTemp^ ERROR

I get this error or script crashes

And yes ofc I declared $oIE as Global. I know about that IETagNameGetCollection function there is an index which can I use but not working for me..

In this line I tried to add index

$oButtons = _IETagNameGetCollection ($oIE, "button", 2) ; 2 is an index of 2nd button but it returns me similar error or script crashes

@jdelaney No there is not any <table> tag if you mean that, just the <div> tag

Link to comment
Share on other sites

Notice that your error is in reference to $oTemp, and your provided code does not include that variable.  Unable to reproduce.

Also, it doesn't NEED to be a table, that was just a suggestion.  If the div includes some id or unique attribute, you can use that.  If not, look at it's parent node up the chain until you do find something.

 

Edit: ah, the function includes an $oTemp.  Turn on the error handler, and you will be fine.

_IEErrorHandlerRegister

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
Link to comment
Share on other sites

Yeah, edited my last one.  In my experience, the browser can periodically be in a state where the DOM is not accessible.  The error handler will catch that, and proceed.

Edited by jdelaney
IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.
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...