I have looked but I simply cannot find an answer to what I expect should be a very simple task.
I have navigated to a page that contains a known javascript variable.
eg: var foo='my variable text';
How can I extract that value ('my variable text') using iMacros browser? Is that even possible to do directly?
Or, would I have to execute javascript to place that variable's value into an input or tag, that iMacros can then extract from?
Many thanks in advance.
You can use the URL GOTO
method to call a javascript function, which will load the value inside the input element. Please checkout the below example where I have replicated the same.
HTML:
<script>
var a = "naren";
</script>
<input type="text" id="naren"/>
IMacros:
VERSION BUILD=9030808 RECORDER=FX
TAB T=1
URL GOTO=javascript:{(function<SP>(){console.log(document.getElementById(a).value='works!')})()}
So I have made a mockup page with the html as above, then ran the below imacros.
Some points you need to know about calling the imacros script are:
I have wrapped the anonymous function as an iife
, long story short, the function will get executed immediately.
If you visit the IMACROS URL wiki page
There is a line which tells us.
The URL GOTO command by default outputs the result of the evaluated Javascript expression on a new page in the current tab. If you want to manipulate an element on the page and don't want the result to be processed by the URL GOTO command, you need to wrap it in some other call or expression that does not evaluate to any value.
For example, to change the value of the Name field on the demo Fill Form page, you can wrap the call in console.log() as follows:
URL GOTO=http://demo.imacros.net/Automate/TestForm1 URL GOTO=javascript:console.log(document.getElementById("name").value='Test');
So I have implement the above statement by wrapping the assignment done to the input element inside a console.log
.
Please let me know if you have issues implementing this solution!