Refresh the page if a word found imacros - 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
}

Related

How to go to extracted links with iMacros?

I can't really understand iMacros syntax.
What I'm trying to do.
1) Go to first page of my blog
2) Find link containing word "post"
3) Go to link found on step 2
4) Return to previous page
5) Find another same link
6) If no same links, find link with "next" word (it means next page)
7) Go to that page
8) Return to step 2
sounds like a plan. Then script will open all posts on page, save them and go to another page.
How can I do this? I tried something with TAG and POS attributes, but they show only errors
You've got it wrong. iMacros CAN'T do that. iMacros can't do IF clauses. For that you have to use JavaScript scripting.
1) Go to first page of my blog
2) Find link containing word "post"
3) Go to link found on step 2
4) Return to previous page
5) Find another same link
6) If no same links, find link with "next" word (it means next page)
7) Go to that page
8) Return to step 2
This is what you are asking.
var macro;
macro ="CODE:";
macro +="URL GOTO=www.myblog.com"+"\n";
var macro1;
macro1 ="CODE:";
macro1 +="TAG POS=1 TYPE=A ATTR=TXT:*post* EXTRACT=HREF"+"\n";
var macro2;
macro2 ="CODE:";
macro2 +="URL GOTO={{link}}"+"\n";
var macro3;
macro3 ="CODE:";
macro3 +="TAG POS=1 TYPE=A ATTR=TXT:*next* EXTRACT=HREF"+"\n";
//go to link
iimPlay(macro)
//extract the link on page with text post
iimPlay(macro1)
var link=iimGetLastExtract();
//if there is such a link go to it
if(link!="#EANF#")
{
iimSet("link",link)
iimPlay(macro2)
}
//go to previous page
iimPlay(macro)
//extract the link with text post
iimPlay(macro1)
link=iimGetLastExtrac();
//if there is not a link like that extract link with text next
if(link=="#EANF#")
{
//extract link with text next
iimPlay(macro3)
var next_link=iimGetLastExtract();
//if there is a link with text next navigate to it
if(next_link!="#EANF#")
{
//navigate to link with text
iimSet("link",next_link)
iimPlay(macro2)
}
}
So try working on this and you will get the answer to your macro. And this has to be placed in .js file and NO OTHER EXTENSION!

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.

I am using i-macro on a website to perform different actions on a site

I want i-macro to do something like this:
1 - go to specific url like: http://www.xyz.com
2 - if there is an error in loading the url, then perform this thing
TAG POS=1 TYPE=IMG ATTR=SRC:http://www.xyz.com
3 - else load the page
my question is how can i accomplish this task
Since there is no IF statement in imacros you'll need to use javascript (for example). the code would be like this:
var ret=iimPlay("code:url goto=http://xyz.com");
if (ret<0){
iimPlay("code:TAG POS=1 TYPE=IMG ATTR=SRC:http://www.xyz.com");
}
else{
iimPlay("code:refresh");
}
save it as js file and run in firefox imacros.

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}}

Click a button if text exist in page with 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;
}