I am writing a script for a login page. But I have a captcha that I want to handle.
Selenium can't handle captcha.
While website using captcha for the same reason so no one can automate their website using any robots.
You can ask your developers to provide you special environment where they bypass that captcha features or expose captcha value on DOM too so you can get the value of captcha on run time.
There is some 3rd party libraries are present who claim that they can automate captcha too but I never tried and heard that they are not efficient too.
Some references :- How to read the text from image (captcha) by using Selenium WebDriver with Java
http://www.mythoughts.co.in/2012/11/automatingbreaking-captcha-using.html#.Vt5psdx94x8
Most captchas solvers are paid. Several examples in captchas solves are:
The tesseract
library solve some examples simples in captcha.
Here, give my method a try (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);
}
}
}
//reading text from images
using(var engine = new TesseractEngine(“tessdata path here”, “eng”, EngineMode.Default))
{
Page ocrPage = engine.Process(Pix.LoadFromFile(filePath + “CaptchImage.png”), PageSegMode.AutoOnly);
var captchatext = ocrPage.GetText();
}
}
source: https://thedotnetlight.wordpress.com/2018/02/16/read-captcha-image-in-selenium-c/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With