使用Selenium IDE 3.4单击Google Recaptcha v2复选框

时间:2019-01-10 04:29:22

标签: selenium-ide

我有一个网站在某些页面上使用Google Recaptcha v2进行用户验证。我正在暂存环境中试用Chrome(v3.4.4)中的新Selenium IDE扩展,但无法单击Recaptcha中的复选框。

在Firefox的旧Selenium IDE中,我可以在id = my_recaptcha或css = g-recaptcha上执行Click命令。但这似乎不再起作用。我尝试选择iframe,在页面上的X,Y坐标上单击,再单击id,似乎没有任何效果。关于如何使新的Selenium IDE进入iframe并单击Recaptcha复选框的任何想法?

(注意-由于我在暂存站点上使用Selenium IDE,并且使用Google测试环境sitekey,所以实际上我不需要Selenium通过真实的recapcha测试—它要做的就是选中iframe和Recaptcha将始终成功。)

这是一些非常简单的示例代码:

<html>
<head>
    <script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
    <!-- site key is the google testing key, this is only in use on my staging site where I test with Selenium -->
    <div id="my_recaptcha" class="g-recaptcha" data-sitekey="6LeIxAcTAAAAAJcZVRqyHh71UMIEGNQ_MXjiZKhI"></div> 
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您添加了selectFrame命令吗?这个kntu selenium ide宏对我有用:

您可以将代码复制并粘贴到source code tab中并运行它:

{
  "Name": "f1",
  "CreationDate": "2019-1-10",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://www.google.com/recaptcha/api2/demo",
      "Value": ""
    },
    {
      "Command": "selectFrame",
      "Target": "index=0",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "//*[@id=\"recaptcha-anchor\"]/div[5]",
      "Value": ""
    }
  ]
}