6

I am writing a script for a login page. But I have a captcha that I want to handle.

Akshay
  • 135
  • 1
  • 2
  • 10

3 Answers3

8

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

Shubham Jain
  • 16,610
  • 15
  • 78
  • 125
1

Most captchas solvers are paid. Several examples in captchas solves are:

  • DeathByCaptcha
  • 2Captcha
  • AntiCaptcha
  • Decaptcher

The tesseract library solve some examples simples in captcha.

CDspace
  • 2,639
  • 18
  • 30
  • 36
iNktown
  • 11
  • 1
1

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/

Dale K
  • 25,246
  • 15
  • 42
  • 71
  • Link-only answers are generally [frowned upon](http://meta.stackexchange.com/a/8259/204922) on Stack Overflow. In time it is possible for links to atrophy and become unavailable, meaning that your answer is useless to users in the future. It would be best if you could provide the general details of your answer in your actual post, citing your link as a reference. – Athul Nath Mar 16 '18 at 10:36