【问题标题】:How to Find the reCAPTCHA element and click on it in c# Selenium如何在 c# Selenium 中找到 reCAPTCHA 元素并单击它
【发布时间】:2021-09-07 18:43:13
【问题描述】:

大家好,我需要帮助。有网址:http://lisans.epdk.org.tr/epvys-web/faces/pages/lisans/petrolBayilik/petrolBayilikOzetSorgula.xhtml。正如您在屏幕截图中看到的,我需要单击复选框验证码。

https://i.stack.imgur.com/xjXaA.png

这是我的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Support.UI;

namespace AkaryakitSelenium
{
    class Program
    {
        private static string AkaryakitLink = "http://lisans.epdk.org.tr/epvys-web/faces/pages/lisans/petrolBayilik/petrolBayilikOzetSorgula.xhtml";
        static void Main(string[] args)
        {
           
           IWebDriver driver = new ChromeDriver();
            IJavaScriptExecutor js = driver as IJavaScriptExecutor;
            driver.Navigate().GoToUrl(AkaryakitLink);
            var kategoriCol = driver.FindElements(By.CssSelector(".ui-selectonemenu-trigger.ui-state-default.ui-corner-right"));
            var x = kategoriCol[3];
            x.Click();
            var deneme = driver.FindElement(By.Id("petrolBayilikOzetSorguKriterleriForm:j_idt52_1"));
             deneme.Click();
           
            
            var check = driver.FindElement(By.Id("recaptcha-anchor"));
            
            check.Click();
        }
    }
}

最后是我面临的这个错误:

"OpenQA.Selenium.NoSuchElementException: '没有这样的元素:无法 定位元素:{“方法”:“css 选择器","选择器":"#recaptcha-anchor"}"

感谢您的帮助。

【问题讨论】:

    标签: c# selenium selenium-webdriver webdriver recaptcha


    【解决方案1】:

    您可以使用 Selenium 绕过验证码。
    它旨在避免自动访问网页,如here 和许多其他地方所述。

    【讨论】:

      【解决方案2】:

      您要查找的元素在 iframe 内:

      //iframe[@title='reCAPTCHA']
      

      首先你需要像这样切换到 iframe:

      new WebDriverWait(driver, TimeSpan.FromSeconds(3)).Until(ExpectedConditions.FrameToBeAvailableAndSwitchToIt(By.XPath("//iframe[@title='reCAPTCHA']")));
      

      然后您可以对其执行单击

      var check = driver.FindElement(By.Id("recaptcha-anchor"));
      check.Click();
      

      PS : 验证码并不是要自动化的。因为 Captcha 代表 CAPTCHA 代表完全自动化的公共图灵测试,以区分计算机和人类。

      【讨论】:

      • 我可以通过您的提示点击验证码。我想问一下广告拦截器是否有助于验证码自动化,我们可以将广告拦截器添加到 selenium
      • 好吧,几乎没有办法解决它stackoverflow.com/questions/58872451/…,而且很多时候这已经在 SO 被问到了。我个人从来没有自动化过任何验证码,因为如果我自动化的话,那将是一个糟糕的验证码:)。话虽如此,如果应用程序属于您的组织。您可以要求您的开发人员或 OPS 设置一个没有验证码的环境,希望您的测试能够通过。
      • 感谢您的提示我想自动化验证码,因为我正在为该网站开发爬虫,所以我编写了用于手动验证码解决问题的代码。它一直等到验证码被解决。
      猜你喜欢
      • 2019-05-23
      • 2021-12-26
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 2017-09-14
      • 2020-07-09
      • 2023-03-15
      相关资源
      最近更新 更多