如何使用imacros浏览器提取javascript变量值? [英] How to extract javascript variable value using imacros browser?

查看:114
本文介绍了如何使用imacros浏览器提取javascript变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看过但是我找不到我期望应该是一个非常简单的任务的答案。



我已经导航到包含已知javascript的页面变量。



例如:var foo ='my variable text';



如何提取该值( '我的变量文字')使用iMacros浏览器?甚至可以直接做吗?



或者,我是否必须执行javascript将该变量的值放入输入或标签中,然后iMacros可以从中提取? / p>

非常感谢提前。

解决方案

你可以使用 URL GOTO 调用javascript函数的方法,该函数将加载input元素中的值。请查看下面我已复制相同内容的示例。



HTML:

 <脚本> 
var a =naren;
< / script>
< input type =textid =naren/>

IMacros:

  VERSION BUILD = 9030808 RECORDER = FX 
TAB T = 1
URL GOTO = javascript:{(function< SP>(){console.log(document .getElementById(a).value ='works!')})()}

所以我有用上面的html做了一个模型页面,然后运行下面的imacros。



关于调用imacros脚本你需要知道的一些要点是:



我已将匿名函数包装为 iife ,长话短说,该功能将立即执行。



如果您访问 IMACROS URL维基页面 有一条线告诉我们。


URL GOTO命令默认输出结果在当前选项卡的新页面上评估的
Javascript表达式。如果你想
操纵页面上的一个元素并且不希望结果是由URL GOTO命令处理的
,你需要将它包装在其他一些
调用或表达式中没有评估为任何值。



例如,要更改演示Fill
表单页面上的名称字段的值,您可以将调用包装起来console.log()如下:



URL GOTO = http://demo.imacros.net/Automate/TestForm1 URL
GOTO = javascript:console.log(document.getElementById(name)。value ='Test') ;


所以我通过将完成的赋值包装在<$ c $中的输入元素中来实现上述语句c> console.log 。



如果您在实施此解决方案时遇到问题,请与我们联系!


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!

这篇关于如何使用imacros浏览器提取javascript变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆