Type out lines by column number each run

Discussions and Tech Support specific to the iMacros Firefox add-on.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

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
Shoez
Posts: 3
Joined: Sat Nov 20, 2021 11:33 am

Type out lines by column number each run

Post by Shoez » Sat Nov 20, 2021 12:17 pm

Hello, I'm using an old version of firefox (38) and imacros (8.9.7) to use custom code.

Code: Select all

Browser Firefox 38.0.6
iMacros for Firefox 8.9.7
Windows 10 64-bit Operating system
I'm asking whether there's a way of typing out lines of text from a '.txt' file onto a website's text area. I have made a version that types out random lines from a text file which I'll include in this post.
Example of what I'm asking (below are lines from a text file):
"line1: type me out first."
"line2: type me out second on second run. "
"line3: type me out last on the last run, then repeat from line1 to line3."
(So each run, it will type out a line, refresh the page, and then on the 2nd run it will type out line2, refresh, and lastly type out line3, refresh, and loop).

Here's my current code, could anyone point out what I could change and where? I'm new to the concept.

Code: Select all

Comment += "CODE:" + "\n";
Comment += "SET !ERRORIGNORE YES" + "\n";
Comment += "SET !TIMEOUT_PAGE 5" + "\n";
Comment += "SET !TIMEOUT_STEP 0" + "\n";
Comment += "SET RANDOMVALUE EVAL(\"Math.floor(Math.random() * ('{{Com_Num}}' *1 + 1)) + 1;\")" + "\n";
Comment += "SET !DATASOURCE text<sp>file1.txt" + "\n";
Comment += "SET !DATASOURCE_LINE {{RANDOMVALUE}}" + "\n";
Comment += "WAIT SECONDS=1" + "\n";
Comment += "EVENT TYPE=CLICK SELECTOR=\"#contenteditable-root\" BUTTON=0" + "\n";
Comment += "EVENTS TYPE=KEYPRESS SELECTOR=\"#contenteditable-root\" CHARS={{!col1}}" + "\n";
Comment += "WAIT SECONDS=2" + "\n";
Comment += "WAIT SECONDS=3" + "\n";
Last edited by Shoez on Sat Nov 20, 2021 3:13 pm, edited 1 time in total.
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Type out lines by column number each run

Post by chivracq » Sat Nov 20, 2021 2:39 pm

Shoez wrote:
Sat Nov 20, 2021 12:17 pm
Hello, I'm using an old version of

Code: Select all

firefox (56) and imacros (8.9.7)
to use custom code.

I'm asking whether there's a way of typing out lines of text from a '.txt' file onto a website's text area. I have made a version that types out random lines from a text file which I'll include in this post.
Example of what I'm asking (below are lines from a text file):
"line1: type me out first."
"line2: type me out second on second run. "
"line3: type me out last on the last run, then repeat from line1 to line3."
(So each run, it will type out a line, refresh the page, and then on the 2nd run it will type out line2, refresh, and lastly type out line3, refresh, and loop).

Here's my current code, could anyone point out what I could change and where? I'm new to the concept.

Code: Select all

Comment += "CODE:" + "\n";
Comment += "SET !ERRORIGNORE YES" + "\n";
Comment += "SET !TIMEOUT_PAGE 5" + "\n";
Comment += "SET !TIMEOUT_STEP 0" + "\n";
Comment += "SET RANDOMVALUE EVAL(\"Math.floor(Math.random() * ('{{Com_Num}}' *1 + 1)) + 1;\")" + "\n";
Comment += "SET !DATASOURCE text<sp>file1.txt" + "\n";
Comment += "SET !DATASOURCE_LINE {{RANDOMVALUE}}" + "\n";
Comment += "WAIT SECONDS=1" + "\n";
Comment += "EVENT TYPE=CLICK SELECTOR=\"#contenteditable-root\" BUTTON=0" + "\n";
Comment += "EVENTS TYPE=KEYPRESS SELECTOR=\"#contenteditable-root\" CHARS={{!col1}}" + "\n";
Comment += "WAIT SECONDS=2" + "\n";
Comment += "WAIT SECONDS=3" + "\n";

+ Quote of your "other Thread" that I disapproved as Duplicate, but I'll still include a Quote as the Content is a bit different...:
... About the Thread Title(s), keep the Term "Extract(ing/ion)" about extracting Data from a Website (using the 'EXTRACT' Mechanism), and rather use "Retrieve"/"Use"/"Pull"/"Read" when retrieving Data from a DataSource...
Thread disapproved, User notified, Reason(s):
- Duplicate...

Disapproving this Thread as Duplicate, I'll approve "the other one" as I "prefer" the Title and which mentions your FCI, and I'll quote this one in my first Reply as the Content of both is a bit different, except the Script...

>>>

Post details
Extracting text file lines from top to bottom
Posted by Shoez » 20/11/2021 - 12:44

Hello, I need help with extracting multiple lines of text from a text file onto a webpage.

I want to type lines of text from top to bottom from a text file. When line1 gets typed out, next run (line2) will be typed out, then line3, and loop.
For example:
col1 (line 1) will be typed into the website's box area,
col2 (line 2) will be typed into the website's box area but on the second run.
col3 (line 3) will be typed into the website's box area last, and then loop (go from line 1 to 3 again).
So I need the lines of text to be typed out into the box area on the website vertically, so one line at a time.
Then, when it reaches line3, it will loop and go from line1 to line3 again.
Example:
"Line1: type me into box.
Line2: type me into box after line1.
Line3: type me into box last, and loop the lines."

Code: Select all

[... Same Script...]
"Comment" is there so it's easier for me to recognise.
I've searched everywhere I could, but nothing is helping me. I'm not great with this, I'm quite new. Any help would mean the world. Thanks.

Alright, as you understood I guess from one Thread being disapproved, "take it easy" with the Forum, no Need to open Duplicates, you can always edit your previous Posts or post some Update "a bit later on" if you need to add more Info, like your OS for example which is (still) missing from your OS...

FCIM...! :mrgreen: (Read my Sig...)
=> iMacros for FF v8.9.7, FF56, OS...?

>>>

+ Parallel Thread on SOF:
- Copy text from top to bottom in imacro javascript

Oh yep...!, and this is "really" the same Thread/Scenario, I was not "really awake", oops...!, when I had posted the following Comment:
I had posted (4 years ago...!) a Technique (in pure '.iim') to get the Total Nb or Lines in your '.txt' File in the following Thread: "Re: Get number of lines from CSV and use as variable?" + same Thread also contains a Technique in (pure) '.js' Code if you "prefer" (but my Method is quicker if you have >100 Rows/Lines), as you'll have to use that Tot_Nb to reverse-retrieve the Rows/Lines from your Input File to re-save it in Reverse-Order... –

chivracq - 20 hours ago
... as because of the Mention/Emphasis on "top to bottom", I had actually understood "bottom to top" and thought "the main Difficulty" of the Scenario was to read/retrieve the Data from your DataSource in Reverse Order, ah-ah...! Ooooops...! :oops: :P :? :shock:

... Alright then, the "Scenario" is pretty "classic" then..., with a "Modulo[3]" Implementation to rotate between the 3 Cols... :idea:
I'll elaborate further after you've added your OS for your FCI... (Applies also to your parallel Thread on SOF btw..., maintain "the same Quality" on both Sites...)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Shoez
Posts: 3
Joined: Sat Nov 20, 2021 11:33 am

Re: Type out lines by column number each run

Post by Shoez » Sat Nov 20, 2021 4:38 pm

Code: Select all

Browser Firefox 38.0.6
iMacros for Firefox 8.9.7
Windows 10 64-bit Operating system
Last edited by chivracq on Sat Nov 20, 2021 8:18 pm, edited 1 time in total.
Reason: Quote removed for Readability...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Type out lines by column number each run

Post by chivracq » Sat Nov 20, 2021 8:40 pm

Shoez wrote:
Sat Nov 20, 2021 4:38 pm

Code: Select all

Browser Firefox 38.0.6
iMacros for Firefox 8.9.7
Windows 10 64-bit Operating system

OK, Thanks, and you'll also edited and added that Info to your OP, perfect...! :D
Thread/Qt on SOF not edited/updated (yet), but OK, fair enough...

I removed your "huge" Quote for "Readability", you don't need to quote yourself again with several Levels of nested Quotes, to simply mention your FCI...

Hum, FF38...!?, you previously had FF56 mentioned, which sounded very "plausible", as FF56 was indeed the last FF Version to support iMacros v8.9.7 for FF, even if I usually "recommend" FF v55.0.3 rather than FF56..., but FF38 is pretty old, I'm not even sure that v8.9.7 works in that Version, I would rather have expected v8.8.7 as the iMacros (for FF) Version..., but OK, anyway, that won't change anything to your Scenario...

>>>

Alright, then..., the Functionality that you want is pretty simple actually, instead of your 'random([1-3])' that you are currently using to rotate between the 3 Lines (and not "Cols" like I had mentioned in my previous Reply) from your DataSource, you need to use 'n Modulo[3]' (=> n%3) for `!DATASOURCE_LINE` where 'n' is your "Loop", either the "raw" `!LOOP` if you were using an '.iim' Script, or the Loop Number from your `for` Loop as you are using a '.js' Script... :idea:

=> The Solution is simply:

Code: Select all

n%3
Fairly simple, no...!? :P 8)

>>>

Oh yeah...!, and some "Recommendation", I nearly always consider using `EVAL()` in an on-the-fly generated Script in a '.js' Script "Bad Practice", as the "Purpose" of the iMacros `EVAL()` Command is exactly to be able to use JavaScript in an '.iim' Script, while you are already in a JS Environment, ah-ah...!, + using `EVAL()` the way you do also brings some extra Levels of nested Escaping for Single/Double Quotes, it will be much simpler for you if you compute that 'n%3' Value "outside" of the on-the-fly '.iim' Script and pass it to it like you probably already do for your 'Com_Num' Var using `iimSet()`... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
Shoez
Posts: 3
Joined: Sat Nov 20, 2021 11:33 am

Re: Type out lines by column number each run

Post by Shoez » Sat Nov 20, 2021 10:41 pm

chivracq wrote:
Sat Nov 20, 2021 8:40 pm
Shoez wrote:
Sat Nov 20, 2021 4:38 pm

Code: Select all

Browser Firefox 38.0.6
iMacros for Firefox 8.9.7
Windows 10 64-bit Operating system
Alright, then..., the Functionality that you want is pretty simple actually, instead of your 'random([1-3])' that you are currently using to rotate between the 3 Lines (and not "Cols" like I had mentioned in my previous Reply) from your DataSource, you need to use 'n Modulo[3]' (=> n%3) for `!DATASOURCE_LINE` where 'n' is your "Loop", either the "raw" `!LOOP` if you were using an '.iim' Script, or the Loop Number from your `for` Loop as you are using a '.js' Script... :idea:

=> The Solution is simply:

Code: Select all

n%3
Fairly simple, no...!? :P 8)

>>>

Oh yeah...!, and some "Recommendation", I nearly always consider using `EVAL()` in an on-the-fly generated Script in a '.js' Script "Bad Practice", as the "Purpose" of the iMacros `EVAL()` Command is exactly to be able to use JavaScript in an '.iim' Script, while you are already in a JS Environment, ah-ah...!, + using `EVAL()` the way you do also brings some extra Levels of nested Escaping for Single/Double Quotes, it will be much simper for you if you compute that 'n%3' Value "outside" of the on-the-fly '.iim' Script and pass it to it like you probably already do for your 'Com_Num' Var using `iimSet()`... :idea:
I don't know if I've done this right, can you double check if I've done what you said to do? I don't know where exactly to put things, I don't have great understanding skills.

Code: Select all

var Comment = "";
Comment += "CODE:" + "\n";
Comment += "SET !ERRORIGNORE YES" + "\n";
Comment += "SET !TIMEOUT_PAGE 5" + "\n";
Comment += "SET !TIMEOUT_STEP 0" + "\n";
Comment += "SET !DATASOURCE text<sp>file.txt" + "\n";
Comment += "SET !DATASOURCE_LINE 'n Modulo[3]' n%3" + "\n";
Comment += "WAIT SECONDS=1" + "\n";
Comment += "EVENT TYPE=CLICK SELECTOR=\"#contenteditable-root\" BUTTON=0" + "\n";
Comment += "EVENTS TYPE=KEYPRESS SELECTOR=\"#contenteditable-root\" CHARS={{!col1}}" + "\n";
Comment += "WAIT SECONDS=2" + "\n";
Comment += "TAG POS=3 TYPE=TP-YT-PAPER-BUTTON ATTR=ID:button" + "\n";  
Comment += "WAIT SECONDS=3" + "\n";
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Type out lines by column number each run

Post by chivracq » Sat Nov 20, 2021 11:26 pm

Shoez wrote:
Sat Nov 20, 2021 10:41 pm
I don't know if I've done this right, can you double check if I've done what you said to do? I don't know where exactly to put things, I don't have great understanding skills.

Code: Select all

var Comment = "";
Comment += "CODE:" + "\n";
Comment += "SET !ERRORIGNORE YES" + "\n";
Comment += "SET !TIMEOUT_PAGE 5" + "\n";
Comment += "SET !TIMEOUT_STEP 0" + "\n";
Comment += "SET !DATASOURCE text<sp>file.txt" + "\n";
Comment += "SET !DATASOURCE_LINE 'n Modulo[3]' n%3" + "\n";
Comment += "WAIT SECONDS=1" + "\n";
Comment += "EVENT TYPE=CLICK SELECTOR=\"#contenteditable-root\" BUTTON=0" + "\n";
Comment += "EVENTS TYPE=KEYPRESS SELECTOR=\"#contenteditable-root\" CHARS={{!col1}}" + "\n";
Comment += "WAIT SECONDS=2" + "\n";
Comment += "TAG POS=3 TYPE=TP-YT-PAPER-BUTTON ATTR=ID:button" + "\n";  
Comment += "WAIT SECONDS=3" + "\n";

Hum, again, "take it easy" with unnecessary extra Levels of Quoting, you can quote me if you want, but you don't need to quote yourself (your previous Post) again, this last Reply of yours has nothing related to your FCI anymore... But OK, don't "worry", I will clean up the Thread "at the end", if "too much Quoting" hinders Readability... :|

>>>

Ah-ah...!, nope, not good...! :P :shock:

This Line:

Code: Select all

Comment += "SET !DATASOURCE_LINE 'n Modulo[3]' n%3" + "\n";
Well, "n Modulo[3]" that I used in my previous Reply is simply how I call the Technique that you need (or can use) (... and apparently I'm not the only one, ah-ah...! :wink: ), and "n%3" is how to implement it in pure JS, either in `EVAL()` if you were using an '.iim' Script, or in "pure" JS in your '.js' Script. :idea:

To understand the Mechanism, try looping the following mini-Script, say, 10 times for example:

Code: Select all

SET Modulo_3 EVAL("var n='{{!LOOP}}'; var z=n%3; z;")
PROMPT LOOP:<SP>_{{!LOOP}}_<BR>Modulo_3:<SP>_{{Modulo_3}}_
And that Method would work if using an '.iim' Script (in pure '.iim'), I never use '.js' Scripts myself, so I always implement Solutions that would work in pure '.iim'. If it works in "pure" '.iim', then you can (nearly) always convert it to a '.js' Implementation, => in this Case with a "main" '[1-n]' `for` Loop in JS like you are "probably" already doing... (I don't know, you didn't post that part... :P )

>>>

Another Solution/Implementation you could also use, but only with a '.js' Script, would be to use a "main" '[1-n]' `for` Loop, and a nested '[1-3]' `for` Loop inside the main Loop. That's another Possibility, if you "don't like" the 'Modulo' Operator... :idea: :(

>>>

And hum, I "finally" understood why I keep/kept getting "a bit confused" about your Scenario, and mentioning "Cols" instead of "Lines", that's because your Thread/Qt on SOF is actually about Cols, and is not "exactly" the same like this current Thread on our Forum...:
... to copy text top to bottom to another notepad file...
+
I want the macro to send text from each column in a vertical pattern. E.g: column one will be sent first, then next run it will move onto the 2nd column and repeat for all columns.
... And in this current Thread (on our Forum), you already have the "vertical" DataSource File with the 3 Rows/Lines. And what you want in your Thread on SOF is a bit different, the easiest way to do what you want, is simply to open your ("horizontal") '.txt' File in 'Excel', select the 3 Cells, => Copy => "Paste Special" + "Transpose", and re-save your File... :idea:

Can also be done from iMacros, I have 2 Methods to do that if you still need that Func from an iMacros Script, one in pure '.iim', and one in pure '.js', ah-ah...!, but the '.iim' one can also be ported to '.js'... 8)
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: Type out lines by column number each run

Post by chivracq » Thu Nov 25, 2021 6:18 pm

And...?, any Progress/Follow-up on this one..., about 5 days later...?, as I "see" that you've opened a New Thread on SOF (and that I have already answered btw, no "Reaction" there either, but I "only" posted my Answer 3h ago...), without finishing this current Thread "correctly"... :(

I stop helping Users when they don't react/follow up (anymore) and finish their Threads "correctly" and useful for other Users by sharing their Implementation/working Script..., just saying... :idea:
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
techimac
Posts: 482
Joined: Fri Feb 20, 2015 9:27 pm

Re: Type out lines by column number each run

Post by techimac » Fri Jan 14, 2022 12:11 am

Code: Select all

var Comment = "";
Comment += "CODE:" + "\n";
Comment += "SET !ERRORIGNORE YES" + "\n";
Comment += "SET !TIMEOUT_PAGE 5" + "\n";
Comment += "SET !TIMEOUT_STEP 0" + "\n";
Comment += "SET !DATASOURCE text<sp>file1.txt" + "\n";
Comment += "SET !DATASOURCE_LINE {{Row}}" + "\n";
Comment += "WAIT SECONDS=1" + "\n";
Comment += "EVENT TYPE=CLICK SELECTOR=\"#contenteditable-root\" BUTTON=0" + "\n";
Comment += "EVENTS TYPE=KEYPRESS SELECTOR=\"#contenteditable-root\" CHARS={{!col1}}" + "\n";
Comment += "WAIT SECONDS=2" + "\n";
Comment += "refresh" + "\n";
Comment += "WAIT SECONDS=3" + "\n";

while(true)
{
for (var Row=1;Row<=3;Row++)
{
iimSet("Row",Row)
iimPlay(Comment)
}
}
Available for custom iim, javascript iMacros scripts
Post Reply