是否可以在SeleniumIDE ++ / Kantu中执行循环任务,如果最后一个失败而不是停止所有任务,则在下一个任务开始时执行?

时间:2019-06-19 09:24:07

标签: selenium selenium-ide kantu

我的任务/机器人进入随机网站,无论我如何努力防止失败,都会有一些。

但是我可以说我的机器人在70%的时间内都能正常工作。我循环了项目,但是当它失败时,它退出了循环(我的意思是启动任务为循环,而不是while循环,始终适用于两者)

有没有办法让它在失败时再次出现?

1 个答案:

答案 0 :(得分:0)

  

有没有办法让它在失败时再次出现?

是的。如果出现问题(例如,找不到元素,网页未加载,...),您可以使用OnError command重新启动循环。

这是一个示例宏:

如果发生错误,宏将跳转到“ restart_loop”标签,并重复当前循环。

{
  "Name": "restart1",
  "CreationDate": "2019-6-19",
  "Commands": [
    {
      "Command": "onError",
      "Target": "#goto",
      "Value": "restart_loop"
    },
    {
      "Command": "store",
      "Target": "fast",
      "Value": "!replayspeed"
    },
    {
      "Command": "store",
      "Target": "15",
      "Value": "!TIMEOUT_WAIT"
    },
    {
      "Command": "store",
      "Target": "60",
      "Value": "!TIMEOUT_PAGELOAD"
    },
    {
      "Command": "store",
      "Target": "1",
      "Value": "i"
    },
    {
      "Command": "label",
      "Target": "restart_loop",
      "Value": ""
    },
    {
      "Command": "if_v2",
      "Target": "${!statusOK} == false",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "ERROR!!! => restart from top, loop=${i}, status=${!statusOK}",
      "Value": "blue"
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!statusOK"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "label",
      "Target": "start",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://docs.google.com/forms/d/e/1FAIpQLScP-K8zi-9ar0MCq93D3VIFhegSNPveBfdLqiMfTYR9Q1iSKQ/viewform",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "//span[contains(text(),\"UI.Vision IDE\")]",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "//*[text()[contains(.,'Web Testing')]]",
      "Value": ""
    },
    {
      "Command": "clickAndWait",
      "Target": "css=span.quantumWizButtonPaperbuttonLabel.exportLabel",
      "Value": ""
    },
    {
      "Command": "type",
      "Target": "name=entry.1572386418",
      "Value": "this is loop ${i}"
    },
    {
      "Command": "clickAndWait",
      "Target": "//*[@id=\"mG61Hd\"]/div/div[2]/div[3]/div[1]/div[1]/div[2]/div[2]",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "done with ${i}",
      "Value": "green"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${i}) +  Number(1)",
      "Value": "i"
    },
    {
      "Command": "gotoLabel",
      "Target": "start",
      "Value": ""
    }
  ]
}

可以将代码粘贴到source code tab中。