在Chrome上使用Kantu浏览器自动化检查变量值

时间:2018-10-22 16:25:45

标签: javascript selenium selenium-ide web-testing kantu

我在Kantu Browser Automation上使用Chrome

假设我有以下随机网站:

https://www.100lenders.com/index.php

然后我要检查与右上方区域My Loan Amount对应的select元素是否有49个选项?

检查右上角面板预览here

为此,到目前为止,我有以下JSON

{
  "CreationDate": "2018-10-22",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.100lenders.com/index.php",
      "Value": ""
    },
    {
      "Command": "select",
      "Target": "id=loanSelect",
      "Value": "label=$700"
    },
    {
      "Command": "storeEval",
      "Target": "document.querySelectorAll('#loanSelect option').length",
      "Value": "count"
    },
    {
      "Command": "echo",
      "Target": "${count}",
      "Value": ""
    }
  ]
}

其实际输出:49,如您在下面的日志中所见:

[status]
Playing macro 100lenders.com
[info]
Executing:  | open | https://www.100lenders.com/index.php |  | 
[info]
Executing:  | select | id=loanSelect | label=$700 | 
[info]
Executing:  | storeEval | document.querySelectorAll('#loanSelect option').length | count | 
[info]
Executing:  | echo | ${count} |  | 
[echo]
49
[info]
Macro completed (Runtime 4.00s)

我的目标是,如果由于某种原因该数字不是49,请用非绿色的条目突出显示该数字。

关于如何执行此操作的任何想法?

谢谢!

1 个答案:

答案 0 :(得分:0)

  

我的目标是,如果由于某种原因该数字不是49,请用非绿色的条目突出显示该数字。

您已经做了所有的辛苦工作!剩下要做的只是在代码中添加一个if statement

If | ${count} != "49"
  echo | It is NOT 49 | blue
endIf

“蓝色”将echo command打印输出的颜色设置为蓝色。

如果您想抛出错误并停止执行宏,则可以使用ThrowError而不是echo;

If | ${count} != "49"
  ThrowError | It is NOT 49 
endIf