Click a button if text exist in page with iMacros - imacros

I am trying to use iMacros with Firefox to click an UnFollow button ONLY if this code exist on the page...
<small class="follow-status">follows you</small>
If the above does not exist in the page source then it would run this iMacros code...
TAG POS=1 TYPE=DIV ATTR=TXT:UnFollow
From what I have read, there is no if/else type syntax but you can run Javascript with
EVAL("Javascript code here")
If anyone knows how I could do this I could really use the help

You can trick Imacros to make an If statement, but first you have to SET !ERRORIGNORE YES for this macro. Then:
SET EXTRACT NULL
'if this exist you extract the text(even if you know it)
'if doesn't exist should return error but we turned that off; Extract remains Null
TAG POS=1 TYPE=SMALL ATTR=TXT:follows<SP>you EXTRACT=TXT
SET !VAR1 EVAL("var text=\"{{!EXTRACT}}\"; if(text==\"follows you\") text = \"jibber\";else text = \"UnFollow\";text;")
'this one executes if the text is right, if not should give error but we turned that off
TAG POS=1 TYPE=DIV ATTR=TXT:{{!VAR1}}

Use a javascript file for this
run();
function run() {
var exists = doesElementExist();
alert('element exists? ' + exists);
if (exists) {
iimPlay('CODE: TAG POS=1 TYPE=DIV ATTR=TXT:UnFollow');
}
else {
// do something else here
}
}
// test if element exists
function doesElementExist() {
iimDisplay('looking for small element with class "follow-status" on page');
var code = iimPlay('CODE: SET !TIMEOUT_TAG 1\n'
+ 'TAG POS=1 TYPE=SMALL ATTR=CLASS:follow-status EXTRACT=TXT');
if (code !==1) {
return false;
}
var extract = iimGetLastExtract();
if (extract === '#EANF#') {
return false;
}
return true;
}

Related

Imacros extracting

Ji, just a quick question:
Why does that not working properly?
var extract = iimGetLastExtract();
if (extract == "#EANF#") {
break;
};
var extractMacro = "CODE:";
extractMacro += "SAVEAS TYPE=EXTRACT FOLDER=* FILE=scraper.txt" + "\n";
var retcode = iimPlay(extractMacro);
So i want to check if last extract is null and if it is, then break the loop. I want to save !extract to file too, but im getting blank "".
Thats my scraping .iim
TAB T=1
TAG POS=1 TYPE=A ATTR=ONMOUSEDOWN:return<SP>rwt(this,'','','','{{i}}','* extract=href
Try the below code/logic, it should work
iimPlay("CODE:TAG POS=1 TYPE=A ATTR=ONMOUSEDOWN:return<SP>rwt(this,'','','','{{i}}','* extract=href);
var extract = iimGetLastExtract();
while (extract != "#EANF#")
{
iimSet("extract",extract);
iimPlay("CODE:ADD !EXTRACT {{extract}}\n SAVEAS TYPE=EXTRACT FOLDER=* FILE=scraper.txt");
}

iMacros / Select random photo from PC

I need to make iMacros to automatically choose random photo from a folder on my PC. How do I arrange it?
This is the line from iMacros for adding some file manually:
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT=/path/to/the/specific/file
Thanks.
For Shugar
Here’s how my script looks like:
asd.iim
VERSION BUILD=8920312 RECORDER=FX
TAB T=1
URL GOTO=https://onlypult.com/dashboard
TAG POS=1 TYPE=A ATTR=TXT:Calendar
TAG POS=1 TYPE=A ATTR=TXT:+
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT={{rndFilePath}}
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-nextsubmit--2
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-nextsubmit--3
TAG POS=1 TYPE=BUTTON FORM=ID:insta-add-image-form-all ATTR=ID:edit-saveimaage
asd.js
SET folderPath /path/to/folder/
SET rndFilePath EVAL("var arrFile = []; var file = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); file.initWithPath('{{folderPath}}'); var filesEnum = file.directoryEntries; while (filesEnum.hasMoreElements()) {arrFile.push(filesEnum.getNext().QueryInterface(Components.interfaces.nsILocalFile).path);} arrFile[Math.floor(Math.random()*(arrFile.length))];")
PROMPT {{rndFilePath}}
Both files are in folder /iMacros/Macros.
When it comes to line with CONTENT={{rndFilePath}}, nothing happens.
Normally that line looks like this
TAG POS=1 TYPE=INPUT:FILE FORM=ID:insta-add-image-form-all ATTR=ID:edit-insta-image-upload CONTENT=/path/to/content.jpg
The thing is, I need to click and choose some file because there appears dropdown menu when I click on «upload from PC», I cannot just write copy-paste the path to the file. Is it possible?
If you’re using Firefox, the code below returns the full path to a random file from the folder ‘D:\Temp\img’ (specified with the ‘folderPath’ variable).
SET folderPath D:\\\Temp\\\img
SET rndFilePath EVAL("var arrFile = []; var file = Components.classes['#mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile); file.initWithPath('{{folderPath}}'); var filesEnum = file.directoryEntries; while (filesEnum.hasMoreElements()) {arrFile.push(filesEnum.getNext().QueryInterface(Components.interfaces.nsILocalFile).path);} arrFile[Math.floor(Math.random()*(arrFile.length))];")
PROMPT {{rndFilePath}}

Refresh the page if a word found imacros

i want imacros to go to a specific page
and search for a word then refresh the page and loop search if word is found else move to next step
For this you can use javascript scripting. No one will make you a script like this but here is an example.
var macro;
macro ="CODE:";
macro +="TAG POS=1 TYPE=DIV ATTR=TXT:sometext";
if(iimPlay(macro)>0)
{
//text is there
//do something
}
else
{
//text is not there
}

iMacros and many results webpages

I want to fill in a form to search.
Some times there may be 0-19 results, it's ok, it works.
But as long as there's a button "next", I'd like to simulate click on it, then save the page as [namefile]-2, [namefile]-3, [namefile]-4 and so on.
Any idea how you would do this?
var macroClickNext;
macroClickNext ="CODE:";
//this is just example of button not like your case
macroClickNext +="TAG POS=1 TYPE=BUTTON ATTR=TXT:Next";
var macroTestNext;
macroTestNext ="CODE:";
//this is just example of the button not like in your case
macroTestNext +="TAG POS=1 TYPE=BUTTON ATTR=TXT:Next CONTENT=EVENT:MOUSEOVER";
var test=false;
while(true)
{
test=iimPlay(macroTestNext)
if (test>0)
{
iimPlay(macroNext)
}
else
{
break;
}
}
In your example this would do the job. It will click the Next button as long as it's on the page. CONTENT:EVENT:MOUSEOVER is a simple event that hovers over a page element. If it's present it will return true , if not it will return false.

imacro to auto fill a form

I am using the concept of imacro to auto fill a form. I have recorded one and got the script.
For eg:-
VERSION BUILD=7601105 RECORDER=FX
TAB T=1
URL GOTO=http://mysite/home.aspx
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:home.aspx ATTR=ID:ContentPlaceHolder1_txtUsername CONTENT=samual
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ACTION:home.aspx ATTR=ID:ContentPlaceHolder1_txtPassword CONTENT=sampassword
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ID:form1 ATTR=ID:ContentPlaceHolder1_btnLogin
TAG POS=1 TYPE=A ATTR=ID:ContentPlaceHolder1_bpo_TabContainer_tbpnl_lnk_address_0
TAG POS=1 TYPE=INPUT:IMAGE FORM=ID:form1 ATTR=ID:Logout
But my actual requirement is on a button click I need to call this macro and each time the form field value may changes. So I need to dynamically pass these new values to the macros. I am thinking like clicking on that button I will pass new value to these script and save this macro and call that macro. But I am not sure is this the way it will work or is it possible to call a macro (like above) from a program that is created using imacro?
Thanks
Thanks a lot for the answer . It gave some insight. But can you explain a bit more. Because I am completely new to the imacro concept.
<html>
<body>
<script type="text/javascript">
function runimacros() {
var iim1 = new ActiveXObject("imacros");
var ret
ret = iim1.iimInit("-fx");
ret = iim1.iimDisplay("Test Macro");
ret = iim1.iimPlay ("testmacro.iim");//this is the macro which I created in firefox and located C:\Users\MyName\Documents\iMacros\Macros\testmacro.iim
ret = iim1.iimExit();
}
</script>
Click to run iMacros</font>
</body>
</html>
Please note that the macro which created(testmacro.iim) is using firefox and it is located in the above location.
I tried the approach 'http://wiki.imacros.net/JavaScript' but is not working. Am I missing something? I tried the above code in Visual studio and made the default browser as IE. Please give any suggestion.
Thanks
You can't call an Imacros program (.iim) from another one, but you can use javascript to call one or more iim files passing one variable:
var ret;
ret = iimDisplay ("optional message to be displayed on the Imacros banner");
var i='input variable'
ret = iimSet("i", i);
ret = iimPlay("myScript.iim");
/* Check for error */
if (ret = 1) {
/* do useful stuff */
}else
{
err = "The following error occurred: "+iimGetLastError();
alert(err);
};
In the macros script:
'this way we pass the variable to the input field
TAG POS=1 TYPE=INPUT:TEXT ATTR=ID:ContentPlaceHolder1_txtUsername CONTENT={{i}}