help with inefficient code

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
seandamnit
Posts: 18
Joined: Tue Jul 26, 2011 10:08 pm

help with inefficient code

Post by seandamnit » Wed Aug 17, 2011 8:08 pm

Hello,

I have a set of data in a CSV file that looks like this:

Image

my code looks like this:

Code: Select all

VERSION BUILD=7300701 RECORDER=FX
TAB T=1
SET !DATASOURCE orders.csv
SET !DATASOURCE_COLUMNS 100
SET !ERRORIGNORE YES
TAG POS=1 TYPE=SPAN ATTR=TXT:Phones
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL3}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL4}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL5}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL6}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL7}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL8}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL9}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL10}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL11}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL12}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL13}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL14}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL15}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL16}}
SET !TIMEOUT_STEP 0
TAG POS=1 TYPE=LI ATTR=TXT:Item<SP>Code:<SP>{{!COL17}}
SET !TIMEOUT_STEP 0
TAG POS=R1 TYPE=INPUT:TEXT FORM=ACTION:* ATTR=NAME:productRowContainer:* CONTENT={{!COL18}}
This will loop through an order form and auto order product...first finding the specific product SKU, then entering an order qty in the first text box after that product SKU.

I'm looking to make this more efficient and user friendly. Right now you'll see that I enter enough lines of code to cover the max amount of columns I have in the data set, and use TIMEOUT_STEP to skip blank data. While that seems to work as a stop gap, it is unfortunately slower than I'd like, as rows with only 1 product to order still need to run through x more unnecessary steps, and it requires me to update the lines of code depending on my max columns (which will change every time I run this).

Using Firefox

Any suggestions?
MattBell7
Posts: 627
Joined: Thu Nov 26, 2009 11:07 am
Location: United Kingdom

Re: help with inefficient code

Post by MattBell7 » Thu Aug 18, 2011 12:08 pm

easiest option would be to split each item onto seperate lines so with your data you 'd have something more like this:

A1,B1,C1,D1
A1,B1,E1,F1
A1,B1,G1,H1
A2,B2,C2,D2

then your macro won't try to process blank cells, it'll only do what it needs.

The best solution would be to use the scripting interface to control iMacros with variable length loops. but that will be a lot more complex
seandamnit
Posts: 18
Joined: Tue Jul 26, 2011 10:08 pm

Re: help with inefficient code

Post by seandamnit » Thu Aug 18, 2011 5:08 pm

MattBell7 wrote:easiest option would be to split each item onto seperate lines so with your data you 'd have something more like this:

A1,B1,C1,D1
A1,B1,E1,F1
A1,B1,G1,H1
A2,B2,C2,D2

then your macro won't try to process blank cells, it'll only do what it needs.

The best solution would be to use the scripting interface to control iMacros with variable length loops. but that will be a lot more complex
How would I make this loop, with the data organized as your propose? I've organized the data in this manner so that each store's orders are on one line, to make looping possible (I didn't include code for the rest of the script, where it selects a shipping destination and confirms the order)

I don't have the scripting edition, and unfortunately would not be able to justify the cost to my company
MattBell7
Posts: 627
Joined: Thu Nov 26, 2009 11:07 am
Location: United Kingdom

Re: help with inefficient code

Post by MattBell7 » Fri Aug 19, 2011 9:45 am

right, in that case, don't change the format.

in can be done with the freeware version, you'll need to use the Firefox Scripting interface. Have a look on the wiki and it'll show you how.
Post Reply