Source:
Code:
private bool SolveCaptcha(FirefoxDriver webdriver) { var currentFrame = driver.CurrentWindowHandle; var iframe = driver.FindElementsByTagName("iframe"); var el = iframe[0]; driver.SwitchTo().Frame(el); driver.FindElementById("recaptcha-anchor").Click(); Thread.Sleep(1000); driver.SwitchTo().DefaultContent(); iframe = driver.FindElementsByTagName("iframe"); el = iframe[2]; driver.SwitchTo().Frame(el); Thread.Sleep(1000); var text = driver.FindElementByClassName("rc-imageselect-desc-wrapper").Text; if (File.Exists("captcha.png")) { File.Delete("captcha.png"); } var arrScreen = webdriver.GetScreenshot().AsByteArray; using (var screen = new MemoryStream(arrScreen)) { var bmpScreen = new Bitmap(screen); //var captchas = webdriver.FindElementsByClassName("captcha"); //var element = captchas.FirstOrDefault(item => item.GetAttribute("class") == "captcha"); var captcha = webdriver.FindElementById("rc-imageselect"); var rectangle = new Rectangle(captcha.Location, captcha.Size); Image imgCap = bmpScreen.Clone(rectangle, bmpScreen.PixelFormat); imgCap.Save("captcha.png"); using (var msCaptcha = new MemoryStream()) { imgCap.Save(msCaptcha, ImageFormat.Png); } } return false; // noch keine funktion }