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}}
Related
I have just downloaded iMacros, but it changes the source code when I do a 'SAVEAS', compared to when I manually do a 'file' -> 'saveas' -> 'web page HTML only' in Firefox.
How can I make the iMacros 'saveas' be the same as my manual FF save?
My iMacros code is:
URL GOTO=http://www.??????
SAVEAS TYPE=HTM FOLDER=C:\xampp\htdocs FILE=name.htm
Try to use this workaround:
SET myLink http://www.??????
URL GOTO={{myLink}}
SET S "var doc = window.document; var elt = doc.createElement('a'); elt.id = 'myA'; elt.href = '{{myLink}}'; doc.body.appendChild(elt); undefined;"
URL GOTO=javascript:{{S}}
ONDOWNLOAD FOLDER=C:\xampp\htdocs FILE=name.htm
TAG POS=1 TYPE=A ATTR=HREF:{{myLink}} CONTENT=EVENT:SAVETARGETAS
URL GOTO=javascript:{doc.body.removeChild(doc.getElementById("myA"));undefined;}
Trying to automate gmail account creation using iMacros. Facing problem in selecting Gender and Month.
Tried StackOverFlowSolution but it is not working for me. It reports that the command not found. Is it some version mismatch issue or am I missing something?
Can anybody help me in resolving this?
Pasted below the recording along with this fix for reference.
VERSION BUILD=8340723 RECORDER=CR
URL GOTO=https://accounts.google.com/SignUp?dsh=447577167596141020&continue=https%3A%2F%2Faccounts.google.com%2FManageAccount#FirstName=&LastName=
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=ID:createaccount ATTR=ID:PasswdAgain CONTENT=asdf123
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:createaccount ATTR=ID:BirthDay CONTENT=15
TAG POS=1 TYPE=SPAN ATTR=ID:birthyear-placeholder
TAG POS=1 TYPE=INPUT:TEXT FORM=ID:createaccount ATTR=ID:BirthYear CONTENT=1989
TAG POS=1 TYPE=INPUT:TEL FORM=ID:createaccount ATTR=ID:RecoveryPhoneNumber CONTENT=+919791151088
SET monthNum 7
SET monthSlc EVAL("var s = '{{monthNum}}'; switch ('{{monthNum}}') {case '10': s = 'a'; break; case '11': s = 'b'; break; case '12': s = 'c'; break;} '#\\\\:' + s + '>DIV';")
SET listSlc "#BirthMonth>DIV>DIV:nth-of-type(2)"
EVENT TYPE=MOUSEDOWN SELECTOR={{listSlc}} BUTTON=0
EVENT TYPE=MOUSEUP SELECTOR={{listSlc}} BUTTON=0
EVENT TYPE=MOUSEDOWN SELECTOR={{monthSlc}} BUTTON=0
EVENT TYPE=MOUSEUP SELECTOR={{monthSlc}} BUTTON=0
You could definitely do this with imacros. Just a small workaround for this.
Below is the code
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=ID:HiddenBirthMonth CONTENT=05
TAG POS=1 TYPE=INPUT:HIDDEN ATTR=ID:HiddenGender CONTENT=MALE
You can change the above Hidden Input Field's value, and the Month and Gender will get updated (though it might not be visible for the user)
Cheers!
I just checked and actually they seem use div and not a select to do it.
The change is probably triggered by javascript. But I thing it would be a waste to time trying to go through their's.
I just saw that the month change the attribute aria-posinset="6". Here it is for June. I don't think that you can change one with iMacros.
For the current form, dated 11/1/2018. I did the following and it worked to populate gender and month:
TAG POS=1 TYPE=SELECT ATTR=ID:gender CONTENT=3
TAG POS=1 TYPE=SELECT ATTR=ID:month CONTENT=3
The #3 for CONTENT is just the option number to select. You can change that accordingly.
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}}
VERSION BUILD=6060703 RECORDER=CR
URL GOTO=URL
TAG POS=1 TYPE=INPUT:BUTTON ATTR=*
WAIT SECONDS=6
This is the code I'm using for .iim file to click on a button on a website. But I couldn't understand what this code is and what are those tag pos and button attr. When I run this code there's an error like this.
RuntimeError: element INPUT specified by * was not found, line: 3
What is this error and how to tackle it. Please help.
TAG POS=1 TYPE=INPUT:BUTTON ATTR=*
This is a button that submits something. Find that button on web page. Right click on it and select "Inspect Element". Then you will see HTML code of that button.
If it has property name="somename" or id="someid" then you will put
TAG POS=1 TYPE=INPUT:BUTTON ATTR=NAME:somename
TAG POS=1 TYPE=INPUT:BUTTON ATTR=ID:someid
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;
}