How to go to extracted links with iMacros? - 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!

Related

iMacros get text from HTML list

I am using iMacros to try and get the text from each list item. My simple HTML looks like this...
<ul id="fruit_list">
<li>Apple</li>
<li>Pear</li>
<li>Banana</li>
<li>Grape</li>
</ul>
And my iMacros script like this..
TAB T=1
URL GOTO=file:///C:/test.html
TAG POS=1 TYPE=UL ATTR=ID:fruit_list EXTRACT=TXT
The result I get back is ...
AppleApplePearAppleApplePearBananaAppleApplePearAppleApplePearBananaGrape
When what I am expecting is...
Apple Pear Banana Grape
Can anyone show me what I am doing wrong?
There seems to be no easy EXTRACT Option that covers unordered lists that way... The simplest way to go about this is probably to extract the HTML code and parse that in Javascript with SET/EVAL.
It could look like this
TAG POS=1 TYPE=UL ATTR=ID:fruit_list EXTRACT=HTM
SET neat_list EVAL("var e_s = '{{!EXTRACT}}'; e_s.substring(e_s.indexOf('<li>'), e_s.lastIndexOf('<\\/li>')).replace(/(<li>|<\\/li>)/g, '').replace(/ +/g, ' ');")
PROMPT {{neat_list}}
Using Regex to drop all the HTML Tags and additional whitespace to just keep the LI-Item Data you wanted.

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
}

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.

Imacros won't click button?

I'm trying to build a script to post auto blog on Google Sites but the problem is that the button won't click. This is my screenshot: http://i.stack.imgur.com/W5mxq.png
Code Button
<div aria-label="New page" tabindex="0" style="-moz-user-select: none;" role="button" id="create-new-btn" class="goog-inline-block jfk-button jfk-button-standard jfk-button-collapse-left" aria-disabled="false"><span id="sites-collaborator-bar-create-new-page-icon" class="sites-camelot-icon"></span></div>
This is my code in Imacros
Code IMACROS
VERSION BUILD=7601105 RECORDER=FX
TAB T=1
URL GOTO=https://sites.google.com/site/testing/
TAG POS=1 TYPE=DIV ATTR=ID:create-new-btn
This is other code but in Javascript Imacros
Code JAVA
var macro;
macro = "CODE:";
macro += "TAB T=1" + "\n";
macro += "SET !ERRORIGNORE YES" + "\n";
macro += "SET !ERRORCONTINUE YES" + "\n";
macro += "SET !EXTRACT_TEST_POPUP NO" + "\n";
macro += "SET !TIMEOUT 500" + "\n";
macro += "URL GOTO=https://sites.google.com/site/testing/" + "\n";
macro += "TAG POS=1 TYPE=DIV ATTR=ID:create-new-btn" + "\n";
iimPlay(macro)
you can simply load create new page form instead of clicking on the button, since to click you'll have to emulate mouse hovering and use javascript.
Just load: https://sites.google.com/site/your-site/system/app/pages/createPage?source=/home
A possible work around is to use the CLICK command in imacros like so:
VERSION BUILD=7601105 RECORDER=FX
TAB T=1
URL GOTO=https://sites.google.com/site/testing/
CLICK X=1000 Y=10
where X is the distance from the top-left side of the browser to the middle of the button you want to click, and Y is the distance from the top of the browser to the middle of the button you want to click. You are able to measure these distances by doing a print-screen and going into a tool like paint and measuring the pixel distances (or any other tool you find more convenient).
You can try imacros for Firefox instead of Chrome, because in terms of clicking buttons imacros somehow perform better in Mozilla Firefox browser.
Maybe you should try clicking on the span inside that div. Perhaps this trigger the action.
VERSION BUILD=7601105 RECORDER=FX
TAB T=1
URL GOTO=https://sites.google.com/site/testing/
TAG POS=1 TYPE=SPAN ATTR=ID:sites-collaborator-bar-create-new-page-icon

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