C# 如何在selenium C中拍摄reCaptcha图像#

C# 如何在selenium C中拍摄reCaptcha图像#,c#,selenium,recaptcha,captcha,C#,Selenium,Recaptcha,Captcha,当我尝试在selenium中获取reCaptcha v2图像时,我没有得到这样的元素,因为该元素不在主页中 那么我如何才能在selenium C#中获得图片呢 \u driver.Navigate().gotour(“https://www.google.com/recaptcha/api2/demo"); _驱动程序.切换到().帧(0); _driver.FindElement(By.Id(“recaptcha锚”))。单击(); 睡眠(5000); _驱动程序.切换到().帧(0); //

当我尝试在selenium中获取
reCaptcha v2
图像时,我没有得到这样的元素,因为该元素不在主页中

那么我如何才能在selenium C#中获得图片呢

\u driver.Navigate().gotour(“https://www.google.com/recaptcha/api2/demo");
_驱动程序.切换到().帧(0);
_driver.FindElement(By.Id(“recaptcha锚”))。单击();
睡眠(5000);
_驱动程序.切换到().帧(0);
//获取页面中的所有图像
IList images=_driver.FindElements(按.TagName(“img”));
Show(images.Count.ToString());
字符串reCaptchaXpath=“”;
foreach(图像中的var img)
{
如果(img.GetAttribute(“src”)包含https://www.google.com/recaptcha/api2/"))
{
reCaptchaXpath=generateExpath(img,“”);
}
}

编辑-1

下面的代码对我来说很好,并给出了16幅图像

        ChromeDriver _driver;
        _driver = new ChromeDriver();
        _driver.Url = "https://www.google.com/recaptcha/api2/demo";
        Thread.Sleep(5000);

        _driver.SwitchTo().Frame(_driver.FindElement(By.CssSelector("iframe[src*='recaptcha']")));

        _driver.FindElement(By.ClassName("recaptcha-checkbox-checkmark")).Click();

        Thread.Sleep(2000);
        //_driver.SwitchTo().Frame(_driver.FindElement(By.CssSelector("iframe[src*='recaptcha']")));

        _driver.SwitchTo().DefaultContent();
        _driver.SwitchTo().Frame(_driver.FindElements(By.TagName("iframe"))[1]);
        images = _driver.FindElements(By.CssSelector("img"));

        Console.WriteLine(images.Count.ToString());
原始答案

你的问题是下面的声明

_driver.SwitchTo().Frame(0);
您假设只有一个帧。但是有多个帧

你需要使用

_driver.SwitchTo().Frame(_driver.FindElement(By.Css("iframe[src*='recaptcha']")));

请澄清您的具体问题或添加其他详细信息,以突出显示您所需的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。非工作错误:OpenQA.Selenium.NoSuchElementException:'没有这样的元素:无法定位元素:{“方法”:“标记名”,“选择器”:“iframe[src*='recaptcha']”另外,使用CSSSelector时也会出现相同的错误。为什么要使用方法标记名?使用css显示错误?我在selenium C#CssSelector中没有看到css,但它存在相同的问题
_driver.SwitchTo().Frame(_driver.FindElement(By.Css("iframe[src*='recaptcha']")));