Search code examples
firefoximacros

Loop iMacros through CSV file?


Here's what I currently have:

VERSION BUILD=8920312 RECORDER=FX
TAB T=1
URL GOTO=https://www.random-domain.com
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:new_message_form ATTR=ID:my_subject CONTENT=Custom<SP>Title
TAG POS=1 TYPE=TEXTAREA FORM=ID:new_message_form ATTR=ID:my_message CONTENT=Hi,<BR><BR>This<SP>is<SP>a<SP>test<SP>message.<BR><BR>-<SP>Custom<SP>Name
TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:new_message_form ATTR=ID:reply_button

I'm using the iMacros for Firefox plugin. I used to do a lot with iMacros years ago and can't remember how to do a couple of things properly.

  1. I have a CSV file that just has one column and it's a list of URLs that should be rotated through (line-by-line) in the URL GOTO= field.

  2. If the process times out when trying to go to a specific URL or during the submission process, it should timeout and restart the process after 10 seconds.

  3. Is using <SP> required for blank spaces? The plugin is adding it automatically, but I don't remember adding that when working with iMacros a few years ago...

Can anyone help me fix this in the script above? Thanks in advance!


Solution

  • This actually contains 3 columns in the csv, but will help avoid the issue you mention.

    with your .csv, I would recommend saving it from something other than Excel, as it tends to not play nicely with iMacros. I've had good luck with UTF-8 encoded files saved out of Notepad++.

    an apostrophe at the beginning of a line denotes a comment. There are explanations in line below.

    'This will have it continue if it times out
    SET !ERRORIGNORE YES
    'Your ten second requirement
    SET !TIMEOUT_STEP 10
    'prevents testing popup from showing
    SET !EXTRACT_TEST_POPUP NO
    
    'Be sure that the csv has been saved as a UTF-8 encoded csv
    SET !DATASOURCE Datasource.csv
    'This dictates what row to start on
    SET !LOOP 1
    'this connects the loop counter to the row of the csv
    SET !DATASOURCE_LINE {{!LOOP}}
    
    
    URL GOTO={{!COL1}}
    'I usually put a short wait in before I try adding content, you can adjust this.
    WAIT SECONDS=5
    'By referencing them from a csv, you shouldn't need the <SP>
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:new_message_form ATTR=ID:my_subject CONTENT={{!COL2}}
    TAG POS=1 TYPE=TEXTAREA FORM=ID:new_message_form ATTR=ID:my_message CONTENT={{!COL3}}
    TAG POS=1 TYPE=INPUT:BUTTON FORM=ID:new_message_form ATTR=ID:reply_button
    

    I usually add a validation step at the end as well, have iMacros produce a spreadsheet that confirms what has been updated. Helpful if things time out.

    Tack this on the end of the macro if you want to validate

    WAIT SECONDS=5
    
    ADD !EXTRACT {{!COL1}}
    ADD !EXTRACT {{!COL2}}
    TAG POS=1 TYPE=INPUT:TEXT FORM=ID:new_message_form ATTR=ID:my_subject EXTRACT=TXT
    ADD !EXTRACT {{!COL3}}
    TAG POS=1 TYPE=TEXTAREA FORM=ID:new_message_form ATTR=ID:my_message EXTRACT=TXT
    
    SAVEAS TYPE=EXTRACT FOLDER=* FILE=*.csv