Imacros,如果{{! EXTRACT}}是A,用1代替,如果是B,用2代替,如果是C,用3代替。ETC

时间:2018-12-13 09:58:39

标签: javascript imacros

在下一个示例中,我想评估{{!EXTRACT}}的值内容:

macro += 'TAG XPATH="//b[contains(@id,\'errorBlockMessage\')]" EXTRACT=TXT' + "\n";

提取内容的随机结果示例:

实际结果是: 1234

实际结果是: 2345

实际结果是: 3456

实际结果是: 4567

要评估结果,只需替换第一个数字并更改为字母即可。

那么结果将是:

  

如果结果为: 1234

     

新结果是: A

示例2

  

如果结果为: 2345

     

新结果为: B

ETC。

代码示例:

{
EVAL
If {{! EXTRACT}} detect the first number **1** replace all line to **A**

If {{! EXTRACT}} detect the first number **2** replace all line to **B**

If {{! EXTRACT}} detect the first number **3** replace all line to **C**

if {{! EXTRACT}} detect the first number **4** replace all line to **D**


The actual result is:{{!EXTRACT_NEW_VALUE}}
}

真正的例子,但是没有用,因为没有得到值的第一个数字

macro += 'SET !VAR0 EVAL("if (\'{{!EXTRACT}}\' == \'1\') \'A\'; else if (\'{{!EXTRACT}}\' == \'2\') \'B\'; else if (\'{{!EXTRACT}}\' == \'3\')  \'C\'; else if (\'{{!EXTRACT}}\' == \'4'\)  \'D\';")' + "\n";

我现在解决了,只需要使用下一个代码拆分并保留第一个数字即可。

  

宏+ ='SET!VAR0 EVAL(“ var s = \'{{!EXTRACT}} \'; s.split(\'\')[0];”)'   +“ \ n”;

0 个答案:

没有答案