Here, try my method (in c):
public void GenerateSnapshot(string filePath) { IWebDriver driver = new ChromeDriver(); driver.Manage().Window.Maximize(); driver.Navigate().GoToUrl("your url here"); var remElement = driver.FindElement(By.Id("your Captcha Id here")); Point location = remElement.Location; var screenshot = (driver as ChromeDriver).GetScreenshot(); using(MemoryStream stream = new MemoryStream(screenshot.AsByteArray)) { using(Bitmap bitmap = new Bitmap(stream)) { RectangleF part = new RectangleF(location.X, location.Y, remElement.Size.Width, remElement.Size.Height); using(Bitmap bn = bitmap.Clone(part, bitmap.PixelFormat)) { bn.Save(filePath + "CaptchImage.png", System.Drawing.Imaging.ImageFormat.Png); } } }
source: https://thedotnetlight.wordpress.com/2018/02/16/read-captcha-image-in-selenium-c/
source share