如果在页面上找到元素,如何播放代码

How to play code if element found on page

如果在网页上找到变量 "group" 中的元素,则应执行播放代码。如果不是,那么它应该让浏览器返回到上一页。这个if语句应该如何正确执行?

var group = 'TAG POS=1 TYPE=TEXTAREA ATTR=ID:"post_field"';

if(opengroup) {
        iimPlayCode('SET !REPLAYSPEED FAST\nADD !EXTRACT {{!URLCURRENT}}\nSAVEAS TYPE=EXTRACT FOLDER=* FILE=url.txt ')
    } else {
        iimPlayCode('URL GOTO=javascript:window.content.history.back()');
    }

这可以帮助:

var opengroup = iimPlayCode("SET !TIMEOUT_STEP 0" + "\n" + 'TAG POS=1 TYPE=TEXTAREA ATTR=ID:"post_field"');
if (opengroup == 1)
    iimPlayCode('SET !REPLAYSPEED FAST\nADD !EXTRACT {{!URLCURRENT}}\nSAVEAS TYPE=EXTRACT FOLDER=* FILE=url.txt ')
else
    iimPlayCode('URL GOTO=javascript:window.content.history.back()');

我猜您想创建一个 if 语句。这可以通过使用 EVAL 将 java 转换为 iMacros 来实现,这是我曾经使用过的一个示例:

URL GOTO=https://en.wikipedia.org/wiki/Main_Page
WAIT SECONDS=1

'Set the VAR1 to the current url= https://en.wikipedia.org/wiki/Main_Page
SET !VAR1 {{!URLCURRENT}}
WAIT SECONDS=1
URL GOTO=https://en.wikipedia.org/wiki/Portal:Featured_content
WAIT SECONDS=1

'Set the VAR2 to the current url= https://en.wikipedia.org/wiki/Portal:Featured_content
SET !VAR2 {{!URLCURRENT}}

'   1.Now !VAR3 is our answer from the if statement
'   2.We need to assign the text from {{!VAR1}} to a var x,y,z,...
'     In this case, we use the letter d and s, and assign text with \"....\" to the var
'   3.We check if d and s are equal by if (d==s), there is also not equal (d!=s)
'     Or bigger(but only for numbers) (d>s) or smaller (d<s)
'   4.After the if we say what !VAR3 should become if the if statement is right
'     This is done by creating a new var (in this case the x)
'     However the output shall be again a text, so we assign x to https://www.google.de
'     And do this by assigning text to a var with  \"....\"        so in this case {var x = \"https://www.google.de\";}
'   5.After that we add the else, if the statement was false, and assign x to the text, which should
'         !Be VAR3  when the statement was wrong, and we do this again the same way        so in this case {var x=\"https://www.youtube.com\";}
'       6. At the end we "call" x and tell that whatever x has become, it is now !VAR3

SET !VAR3 EVAL("var d=\"{{!VAR1}}\"; var s=\"{{!VAR2}}\" ; if (d==s){var x = \"https://www.google.de\";} else {var x=\"https://www.youtube.com\";} x;")

'checking if code worked (and it did)
URL GOTO={{!VAR3}}

'you can of course change the SET !VAR1 or !VAR2 to some text inside a page, or whatever you like