How to take reCaptcha image in selenium C# How to take reCaptcha image in selenium C# selenium selenium

How to take reCaptcha image in selenium C#


Edit-1

Below code works fine for me and gives 16 images

        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());

Original Answer

Your issue is the below statement

_driver.SwitchTo().Frame(0);

You are assuming there is just one frame. But there are multiple frames

IFrames

You need to use

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