Identify when a button is active

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
shaves
Posts: 77
Joined: Tue Apr 29, 2008 6:50 pm

Identify when a button is active

Post by shaves » Thu Nov 21, 2019 10:48 pm

I've created a macro that adds information to a number of fields in a web-site. It works fairly well. The last step is to push the "submit" button. This button isn't "active" until the web-site performs some validation after data is entered in the last field. I currently have a 7 second wait in my code. 75 % of the time this is sufficient; however, 25 % of the time, the macro errors out because the button isn't "active". If there is a lot of traffic on the web-site or networks or slow, the 7 seconds isn't enough time. I don't want to increase the wait because the macro would be idle for a majority of the time. I'm hoping there is some way to identify when the button is "active. I've looked on the screen to see if there is any change to it once the button becomes active but I haven't see anything to indicate it so far. Thanks for your help......

iMacros 12.5
Windows 7 Enterprise Edition
Office 365
chivracq
Posts: 9645
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify when a button is active

Post by chivracq » Fri Nov 22, 2019 12:18 am

shaves wrote:
Thu Nov 21, 2019 10:48 pm
I've created a macro that adds information to a number of fields in a web-site. It works fairly well. The last step is to push the "submit" button. This button isn't "active" until the web-site performs some validation after data is entered in the last field. I currently have a 7 second wait in my code. 75 % of the time this is sufficient; however, 25 % of the time, the macro errors out because the button isn't "active". If there is a lot of traffic on the web-site or networks or slow, the 7 seconds isn't enough time. I don't want to increase the wait because the macro would be idle for a majority of the time. I'm hoping there is some way to identify when the button is "active. I've looked on the screen to see if there is any change to it once the button becomes active but I haven't see anything to indicate it so far. Thanks for your help......

Code: Select all

iMacros 12.5
Windows 7 Enterprise Edition
Office 365

"... the macro errors out because the button isn't "active"."
=> How does the Macro error out...? What (exact) RuntimeError do you get...?

1- There "must" be stg in the Source that is different between 'Button_Not_Active' and 'Button_Active' that you need to identify and use as 'ATTR' to tag/click that Button, combined with a "SET !TIMEOUT_STEP 10" for example... That's "the Way to go", I would think... :idea:

2- In the same Idea, you could also use 'TAG' + 'XPATH' which supports the 'NOT' Boolean Operator, but I always find 'XPATH'/'REGEXP' a bit complex and not easy to use... (So I never use them, ah-ah...!, I always find/prefer a different Approach... :oops: )

3- Some other Method would be to add a "Conditional 'WAIT'" on top of your current 7 Sec to first "check" if the Button is Active before actually clicking on it, or maybe by already clicking on it, and "stg" gets probably displayed (or not) that you could use to extract + fire the extra 'WAIT', and click (again/conditionally) on the Button...
(And you'll have to "tune" '!TIMEOUT_STEP' between all Statements..., combined with '!ERRORIGNORE'...)

And if you do that twice, you could even shorten the 'WAIT' (in most Cases), to 5+2+3 for example (instead of 7+3)... 8)

4- And 'Relative Positioning' can maybe also be used to "Conditionally" click/tag your Button...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
shaves
Posts: 77
Joined: Tue Apr 29, 2008 6:50 pm

Re: Identify when a button is active

Post by shaves » Fri Nov 22, 2019 5:28 pm

Thanks for the formation. I'll see what I can do with this. Just an fyi......if the button doesn't become active, the macro checks to see if the web-site has moved on to the next page (when the button is clicked). It then writes a message to the Excel file and moves on. The goal is to reduce the number of messages written and complete more of the records. Thanks again for your help. I appreciate the quick response...
chivracq
Posts: 9645
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Identify when a button is active

Post by chivracq » Fri Nov 22, 2019 5:45 pm

shaves wrote:
Fri Nov 22, 2019 5:28 pm
Thanks for the formation. I'll see what I can do with this. Just an fyi......if the button doesn't become active, the macro checks to see if the web-site has moved on to the next page (when the button is clicked). It then writes a message to the Excel file and moves on. The goal is to reduce the number of messages written and complete more of the records. Thanks again for your help. I appreciate the quick response...

OK, then that "next Page" (upon successful clicking on the Button) has some "expected" Content/URL that you can check for a Conditional extra-'WAIT' to then click again on the Button (which probably is not even present anymore on that "next Page") if necessary...

And "writes a message to the Excel file", it's not clear to me if you "do that" through '.vbs'/'.vba' directly from/to 'Excel' (as you mentioned 'Office' in your FCI, and I think I remember you've already had Threads on the Forum about '.vba', if I'm not mistaken...), or using the 'SAVEAS TYPE=EXTRACT' Mechanism to a '.CSV' File (as many "People" associate the '.CSV' File Extension with 'Excel' because they open such Files (once!) with 'Excel', which 'Excel' then "greedily" appropriates to itself, ah-ah...!), but in both Cases, that "Process" will use the '!EXTRACT' Built-in Var, and still from your '.iim' Script, you have Full Control on the Content of that Var (using 'EVAL()') before you "hand it over" to 'SAVEAS' to 'iimGetExtract()'... :idea:

>>>

But OK, this all means that you go for Method_3 that I mentioned in my previous Reply... OK..., but again, if you can identify "stg" that changes between 'Not_Activated' and 'Activated' for your Button, Method_1 would be the best Option in my Opinion, and also the quickest, as iMacros will then handle automatically the Wait on the Button, and will already click on it after 2 Sec if it's already Active then, and won't even wait your current Hard 5 Sec.

And that shouldn't be very hard to identify, I would think..., by looking at the Source before filling any Field, or at least not the last Field, and after all Fields have been filled in and the Validation has taken place and the Button got Activated... There MUST be stg different between the 2, either some "class:Enable(d)/Disable(d)=1/0", or some "OnMouseClick=doAction...whatever", I don't know, I would need to be able to "play" with the Site/Page myself in order to be more precise... :oops:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE').
- I don't even read the Qt if that (required) Info is not mentioned...!
- Script & URL help a lot for more "educated" Help...
Post Reply