Macro running differently while minimized/in background

Discussions and Tech Support specific to the iMacros Firefox add-on.
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
Lightja
Posts: 20
Joined: Tue Aug 30, 2016 3:40 am

Macro running differently while minimized/in background

Post by Lightja » Wed Sep 07, 2016 2:20 am

I've been moving from using the iMacros browser primarily to Firefox. Firefox so far is a lot more reliable and gets far less random errors, plus having multiple profiles is a huge plus. However, the problem is that some of my macros behave differently when minimized. This is especially important if two profiles are running simultaneously, because they need to be the active window for the macro to work.

The specific problem is that when I try to add tags to a photo on tumblr while the window is minimized or is not the active window, instead of acting on the tags, it acts on the photo description instead.

I'm using javascript so that I can add a window.close() at the end of the macro, otherwise it's just one big macro with iimPlay(macro) at the end. The lines for adding tags are:

Code: Select all

macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"#new_post_buttons>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" CHARS=\"tag 1\"" + "\n";
macro += "EVENT TYPE=CLICK SELECTOR=*" + "\n";
macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"#new_post_buttons>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" CHARS=\"tag 2\"" + "\n";
macro += "EVENT TYPE=CLICK SELECTOR=*" + "\n";
macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"#new_post_buttons>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" CHARS=\"tag 3\"" + "\n";
macro += "EVENT TYPE=CLICK SELECTOR=*" + "\n";
if I have the window active, the photo will be posted with all the correct tags labeled. If I have the window minimized or run in the background, instead of adding tags, the photo will edit the description and it will read "tag 1tag 2tag 3" with all tags just bunched up on top of each other.

Anyone know why it acts differently and how I can make it work? Is something not loading fully or something and I need to run a command to make sure it loads fully? Also, I read that it's possible to run the macros on different User Accounts, but I had trouble finding out how to do that, and if it would solve my problem. I suspect that if I was running 5 accounts (which I might eventually do ~20 accounts) I'd need to use something like 20 accounts to make sure they can all be the active window on their respective user accounts when they're run. Surely there's a better way than that.

Also, it might potentially work if I can just start it as a background process, so that it doesn't automatically take focus from what I'm doing. A macro just ran under the browser as I wrote this and it seemed to work OK, but when I test it by starting it manually and then switching focus to another browser (the other browser being chrome, which I don't use with iMacros) it writes the tags in the description instead of as tags. Also, it seems like sometimes the macro interrupts focus, and other times it doesn't, so if there's any way I can get that to be consistent, or understand why it does/doesn't sometimes that would help.

On a side note, is it possible to simulate pressing enter (and other keypresses without specifying a target) on Firefox? Normally I'd use DS (DirectScreen, paid version only) to simulate keypresses, but putting {ENTER} in the CHARS= string of the EVENTS command doesn't seem to work the same way it does with DS. If I can press enter that would simplify my tag input because I could just press enter, then type the next tag, enter, next tag, enter, etc.




System Information:
Windows 10 Enterprise
Firefox v48.0.2 - iMacros for Firefox v8.9.7
Latest System Information:
iMacros 11.1
Windows 10 Enterprise
Firefox v48.0.2 - iMacros for Firefox v8.9.7
Chrome v53.0.2785.89 - iMacros for Chrome v8.4.4
chivracq
Posts: 9309
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Macro running differently while minimized/in background

Post by chivracq » Wed Sep 07, 2016 3:52 am

Lightja wrote:I've been moving from using the iMacros browser primarily to Firefox. Firefox so far is a lot more reliable and gets far less random errors, plus having multiple profiles is a huge plus. However, the problem is that some of my macros behave differently when minimized. This is especially important if two profiles are running simultaneously, because they need to be the active window for the macro to work.

The specific problem is that when I try to add tags to a photo on tumblr while the window is minimized or is not the active window, instead of acting on the tags, it acts on the photo description instead.

I'm using javascript so that I can add a window.close() at the end of the macro, otherwise it's just one big macro with iimPlay(macro) at the end. The lines for adding tags are:

Code: Select all

macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"#new_post_buttons>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" CHARS=\"tag 1\"" + "\n";
macro += "EVENT TYPE=CLICK SELECTOR=*" + "\n";
macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"#new_post_buttons>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" CHARS=\"tag 2\"" + "\n";
macro += "EVENT TYPE=CLICK SELECTOR=*" + "\n";
macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"#new_post_buttons>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" CHARS=\"tag 3\"" + "\n";
macro += "EVENT TYPE=CLICK SELECTOR=*" + "\n";
if I have the window active, the photo will be posted with all the correct tags labeled. If I have the window minimized or run in the background, instead of adding tags, the photo will edit the description and it will read "tag 1tag 2tag 3" with all tags just bunched up on top of each other.

Anyone know why it acts differently and how I can make it work? Is something not loading fully or something and I need to run a command to make sure it loads fully? Also, I read that it's possible to run the macros on different User Accounts, but I had trouble finding out how to do that, and if it would solve my problem. I suspect that if I was running 5 accounts (which I might eventually do ~20 accounts) I'd need to use something like 20 accounts to make sure they can all be the active window on their respective user accounts when they're run. Surely there's a better way than that.

Also, it might potentially work if I can just start it as a background process, so that it doesn't automatically take focus from what I'm doing. A macro just ran under the browser as I wrote this and it seemed to work OK, but when I test it by starting it manually and then switching focus to another browser (the other browser being chrome, which I don't use with iMacros) it writes the tags in the description instead of as tags. Also, it seems like sometimes the macro interrupts focus, and other times it doesn't, so if there's any way I can get that to be consistent, or understand why it does/doesn't sometimes that would help.

On a side note, is it possible to simulate pressing enter (and other keypresses without specifying a target) on Firefox? Normally I'd use DS (DirectScreen, paid version only) to simulate keypresses, but putting {ENTER} in the CHARS= string of the EVENTS command doesn't seem to work the same way it does with DS. If I can press enter that would simplify my tag input because I could just press enter, then type the next tag, enter, next tag, enter, etc.

System Information:
Windows 10 Enterprise
Firefox v48.0.2 - iMacros for Firefox v8.9.7
Hum, I think the Pb comes from those Lines where no Selector is specified:

Code: Select all

EVENT TYPE=CLICK SELECTOR=*
I've only seen/used such (similar) Syntax with 'KEYPRESS' Events for 'Ctrl^c' / 'Ctrl^f' / 'Ctrl^j' / 'F8' / Spacebar / Enter / etc (ie to interact with the DOM) but never with 'CLICK' Events, so I guess when your FF Instance is minimized or in the Background, they don't do anything.

A possible Solution would be indeed to use the ENTER Key, but '{ENTER}' indeed only works with the DS Mode, you need to record typing stg in some Input Field in the EVENT Mode and then pressing ENTER which will record stg with "KEY=13" I think...

And I don't know about your Qt about different User Accounts, I've never tried..., but it sounds heavy/cumbersome to me...
Last edited by chivracq on Wed Sep 07, 2016 5:31 am, edited 1 time in total.
- (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...
Lightja
Posts: 20
Joined: Tue Aug 30, 2016 3:40 am

Re: Macro running differently while minimized/in background

Post by Lightja » Wed Sep 07, 2016 4:52 am

it can't be the second line because the first line inputs the first tag. When it messes up, the first tag gets put in the description box instead, so there has to be something wrong with the first line too.

I tested it to be safe, but actually kinda figured out a solution by testing too.

I replaced:

Code: Select all

EVENT TYPE=CLICK SELECTOR=*
with:

Code: Select all

macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"HTML>BODY>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV:nth-of-type(2)>OL>LI>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" KEYS=\"[13]\"" + "\n";
The problem still remained in that the first tag was input into the description instead of the tags, but because that line simulates pressing enter, instead of continuing to input into the description, it starts inputting into the tag field, so the text basically moved to the next tab.

So what I did is just put

Code: Select all

macro += "EVENTS TYPE=KEYPRESS SELECTOR=\"HTML>BODY>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV:nth-of-type(2)>OL>LI>DIV:nth-of-type(4)>DIV:nth-of-type(2)>DIV>DIV:nth-of-type(3)>DIV>DIV>DIV>DIV>DIV>DIV\" KEYS=\"[13]\"" + "\n";
before the first line of code so that it's executed before, and after every call that actually types something, instead of just after. So what this does is that when the window is in focus, it just tries to input an empty tag, fails, and the typing is still on that same position. However if the window is minimized/not the main focus window, it enters nothing for the description, then automatically makes the next line input to the tags. It's a messy solution, but it works for now.

But the problem still remains that I don't understand the behavior. When the window is in focus, that SELECTOR targets the first tag field, but when the window is minimized/not in focus, it targets the description field. Not sure why this is, but it's not causing me significant problems now, but I'd still like to know.

EDIT: it doesn't actually solve the problem because the line that simulates an enter press doesn't work for some reason.
Latest System Information:
iMacros 11.1
Windows 10 Enterprise
Firefox v48.0.2 - iMacros for Firefox v8.9.7
Chrome v53.0.2785.89 - iMacros for Chrome v8.4.4
Post Reply