Sign in to follow this  
Followers 0
Pain

Need help with finding a button

10 posts in this topic

Hello everyone, I need some help with my script to find and press on a sertain button.

I am Admin on my friends server and need to automate some functions on the Admin panel.

I've tried with _IEFormGetObjByName but the thing is that there is several buttons with same form name.

Same with rest of the _IEGet functions.

There is also several buttons with same name so I can't make it to read the name on the button.

The buttons has no alt tag.

It doesn't work with navigate to the page that the button goes to.

this is how it looks like, I wanna press on "Set to 0" on user 1 (first)

Posted Image

If I can't get this to work I will tell the webmaster (the other admins) to change it when he got time but what would be best to change too then?

Share this post


Link to post
Share on other sites



Can't you tell it which instance in-case of multiple results?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

You can enumerate objects (like buttons) as a collection and walk the collection to find an attribute, like the text on the button or the img src. If you know which instance it is, you can just specify that (i.e. 0 = first, 4 = fifth instance). Look at _IEFormElementGetCollection() in the help file.

:)

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

#4 ·  Posted (edited)

I see what you mean but I can't get it to work.

This is the part that doesn't work.

It only change the name of the button "Move Free" to "Set 0" or press wrong button but as you said 0 = first I assume it should be 2

....
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "Set 0")
_IEFormSubmit ($oForm)


_IELinkClickByText ($oIE, "Yes")
Edited by Pain

Share this post


Link to post
Share on other sites

I see what you mean but I can't get it to work.

This is the part that doesn't work.

It only change the name of the button "Move Free" to "Set 0" or press wrong button but as you said 0 = first I assume it should be 2

....
$oForm = _IEFormGetCollection ($oIE, 0)
$oQuery = _IEFormElementGetCollection ($oForm, 2)
_IEFormElementSetValue ($oQuery, "Set 0")
_IEFormSubmit ($oForm)


_IELinkClickByText ($oIE, "Yes")
You didn't say exactly what you meant to do. You want to click a certain button? Then, assuming your index numbers are right, it's just:

; ...

$oForm = _IEFormGetCollection ($oIE, 0) ; First form
$oElem = _IEFormElementGetCollection ($oForm, 2) ; Third element on form
_IEAction($oElem, "click")

If that's not what you meant to do, please detail the actions you wanted to perform.

:)


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

It's working now, had wrong form :)

$oForm = _IEFormGetCollection ($oIE, 2) 
$oElem = _IEFormElementGetCollection ($oForm, 1)
_IEAction($oElem, "click")

Thanks for the help :P

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

How do I disable "AutoIt Error Line: -1 Error: The requested action with this object has failed."

I get this every time I close my script before it's finished but my script is never ending and I want it to be so.

I have looked in the help file and searched around the forum for 30min without any good result.

I was thinking about

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

after every possible function but it failed, still "AutoIt Error Line: -1"

I even copyied it from the help files.

Here is my script:

Global $Link = "http://blablabla.com"

$oIE = _IECreate ($Link & "search", 0, 1,2000,0)

While 1

$sHTML = _IEDocReadHTML ($oIE)

$o_form = _IEFormGetObjByName ($oIE, "regform")

$o_search = _IEFormElementGetObjByName ($o_form, "search")

$file = FileOpen("search.txt", 0)

If $file = -1 Then

MsgBox(0, "Error", "Unable to open file.")

Exit

EndIf

$line = FileReadLine($file, 1)

...

...

I pressed X when it was still loading IE but IE doesn't have any -1 error if you look in the help file and therefore I believe it's the FileOpen.

Edited by Pain

Share this post


Link to post
Share on other sites

Look in the help file at _IEErrorHandlerRegister() if it's IE generating the error, or look up the OBJ/COM reference section and add a custom COM error handler if it's something else.

:)


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

#9 ·  Posted (edited)

I was looking at it but it made no sence (I'm still new on AutoIt :P)

think I will let this error stay

but once again thanks for the help :)

Edited by Pain

Share this post


Link to post
Share on other sites

I was looking at it but it made no sence (I'm still new on AutoIt :wub:)

Don't be intimidated by it! Just put _IEErrorHandlerRegister(), with no parameters, in somewhere before you do your first _IE* command. Run your script from SciTE and you'll get lots of info about the error in the console. That should do it if it's an IE error in the first place. The technical details of using your own custom error handler are not required, because Dale's default handler is quite good already.

think I will let this error stay

Bad user! No soup for you! :)

but once again thanks for the help :P

You're welcome.

: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

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