代码之家  ›  专栏  ›  技术社区  ›  vivekkurien

如何绕过Google Recaptcha使用Selenium进行测试

  •  0
  • vivekkurien  · 技术社区  · 7 年前

    我正在使用Selenium测试我的基于Spring的Web应用程序。你能建议一个在测试应用程序时绕过google recaptcha的解决方案吗?

    我正在这个环境中运行自动化测试。所以手动检查recaptcha的“我不是机器人”是不可能的。

    为了测试目的,我在下面位置给出的测试环境中使用测试密钥。

    Google reCAPTCHA Testing Key

    enter image description here

    我使用角5作为我的应用程序的前端。我正在使用ng recaptcha库在UI中添加recaptcha。

    3 回复  |  直到 7 年前
        1
  •  6
  •   Ido Ran    7 年前

    我不知道您的确切代码,但是您应该能够使用一个系统属性或一些标志来运行您的服务器,该标志指示RecapTCha应该被禁用,并且首先不要将其添加到表单中。

        2
  •  4
  •   Joby Wilson Mathews    7 年前

    您可以通过在recaptcha中找到复选框的x和y坐标并单击元素来完成此操作。

    WebElement captcha = driver.findElement(By.xpath("html/body/div[1]/div[3]/div[2]/form/div[5]/div"));
            builder.moveToElement(captcha, 50, 30).click().build().perform();
    
        3
  •  1
  •   Nam Nguyen    6 年前

    您应该将驱动程序“切换”到iframe,以精确定位recaptcha的复选框。 命令:

    WebElement iFrame = driver.findElement(By.xpath("xpath_of_reCaptcha_iFrame"));
    driver.switchTo().frame(iFrame);
    

    //现在可以单击recaptcha的复选框。

    WebElement iFrame_checkbox = 
    driver.findElement(By.xpath("xpath_of_reCaptcha_checkbox"));
    iFrame_checkbox.click();