javascriptexcelimacros

how to make page scroll with random pixels and random direction


In imacros I use JavaScript languange and here is some code:

var filesource = imns.Dialogs.browseForFileOpen("Enter file location");
if (filesource)
    fs = filesource.path;
var y =  prompt("start","2");
var z =  prompt("end","20"); 

y=parseInt(y);
z=parseInt(z);

posting="CODE:"+"\n"
posting+="SET !ERRORIGNORE YES"+"\n"
posting+="SET !DATASOURCE {{filesource}}"+"\n"
posting+="SET !DATASOURCE_LINE {{LOOP}}"+"\n"
posting+="SET !WAITPAGECOMPLETE YES"+"\n"
posting+="URL GOTO=https://www.examples.com"+"\n"
posting+="TAG POS=1 TYPE=SPAN ATTR=CLASS:selectBox-arrow"+"\n"
posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_dep_1 CONTENT=%0"+"\n"
posting+="WAIT SECONDS=2"+"\n"

posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_menu_id CONTENT=${{!COL23}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:FILE FORM=ID:frm-add-product ATTR=accept:image/jpeg,image/png CONTENT={{!COL11}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:FILE FORM=ID:frm-add-product ATTR=accept:image/jpeg,image/png CONTENT={{!COL12}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:FILE FORM=ID:frm-add-product ATTR=accept:image/jpeg,image/png CONTENT={{!COL13}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:FILE FORM=ID:frm-add-product ATTR=accept:image/jpeg,image/png CONTENT={{!COL14}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:FILE FORM=ID:frm-add-product ATTR=accept:image/jpeg,image/png CONTENT={{!COL15}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:TEXT FORM=ID:frm-add-product ATTR=ID:p-name CONTENT={{!COL1}}"+"\n"
posting+="TAG POS=1 TYPE=TEXTAREA FORM=ID:frm-add-product ATTR=ID:p-description CONTENT={{!COL6}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:TEXT FORM=ID:frm-add-product ATTR=ID:p-price CONTENT={{!COL3}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:TEXT FORM=ID:frm-add-product ATTR=ID:p-weight CONTENT={{!COL4}}"+"\n"
posting+="TAG POS=1 TYPE=INPUT:RADIO FORM=ID:frm-add-product ATTR=ID:p-condition-new"+"\n"
posting+="TAG POS=1 TYPE=SPAN ATTR=CLASS:selectBox-arrow"+"\n"
posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_dep_1 CONTENT=${{!COL8}}"+"\n"
posting+="WAIT SECONDS=2"+"\n"
posting+="TAG POS=2 TYPE=SPAN ATTR=CLASS:selectBox-arrow"+"\n"
posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_dep_2 CONTENT=${{!COL9}}"+"\n"
posting+="WAIT SECONDS=2"+"\n"
posting+="TAG POS=3 TYPE=SPAN ATTR=CLASS:selectBox-arrow"+"\n"
posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_dep_3 CONTENT=${{!COL10}}"+"\n"
posting+="WAIT SECONDS=2"+"\n"
posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_menu_id CONTENT=$**<SP>Tambah<SP>Etalase"+"\n"
posting+="TAG POS=1 TYPE=INPUT:TEXT FORM=ID:frm-add-product ATTR=ID:p-menu-name CONTENT={{!COL16}}"+"\n"
posting+="TAG POS=1 TYPE=SELECT FORM=NAME:frm_add_product ATTR=NAME:p_menu_id CONTENT=${{!COL16}}"+"\n"
posting+="TAG POS=1 TYPE=a ATTR=ID:invenagebox"+"\n"
posting+="TAG POS=1 TYPE=INPUT:TEXT FORM=ID:frm-add-product ATTR=ID:invenage-value CONTENT={{!COL5}}"+"\n"
posting+="WAIT SECONDS=2"+"\n"
posting+="TAG POS=1 TYPE=BUTTON FORM=ID:frm-add-product ATTR=ID:s-save-prod"+"\n"
posting+="WAIT SECONDS=10"+"\n"
posting+="TAG POS=1 TYPE=ul ATTR=class:square<sp>break-word extract=txt"+"\n"
posting+="set nama EVAL(\"'{{!EXTRACT}}'.replace('Anda telah berhasil memasukkan produk ','')\")"+"\n"
    for (i=y;i<=z;i++){
    iimSet("cat1",cat1);
        iimSet("cat2",cat2);
        iimSet("cat3",cat3); 
        iimSet("ETA",eta);
        iimSet("filesource",fs);
        iimSet("LOOP",i); 
        iimPlay(posting);
        
    } 

So the point is I want to make a page scrolling with random direction and random pixels. I have tried using URL GOTO=javascript:window.scrollBy(0,2000), but it didn't work.

Note : I use Excel comma separated values(CSV) as a source for my code , I was thinking add some random number to each line of Excel sheet , but its didn't work cause URL GOTO=javascript:window.scrollBy(0,2000) this didn't work.


Solution

  • Instead of

    URL GOTO=javascript:window.scrollBy(0,randomNumber)
    

    you can try this code:

    ' your value here '
    SET maxScroll 50
    SET keys EVAL("var k = []; for (i = 0; i <= 1 + Math.floor(Math.random()*{{maxScroll}}); i++) k.push(40); k;")
    EVENTS TYPE=KEYPRESS SELECTOR=* KEYS="[{{keys}}]"
    

    Therefore you don't need to add some random number to each line of the excel sheet.


    Wrapping in JavaScript:

    // ...
    posting += 'SET maxScroll 50' + "\n";
    posting += 'SET keys EVAL("var k = []; for (i = 0; i <= 1 + Math.floor(Math.random()*{{maxScroll}}); i++) k.push(40); k;")' + "\n";
    posting += 'EVENTS TYPE=KEYPRESS SELECTOR=* KEYS="[{{keys}}]"' + "\n";
    // ...