Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to automate captcha using Selenium Webdriver? [closed]

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

like image 621
Akshay Avatar asked Mar 08 '16 05:03

Akshay


3 Answers

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

like image 143
Shubham Jain Avatar answered Nov 15 '22 08:11

Shubham Jain


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

  • DeathByCaptcha
  • 2Captcha
  • AntiCaptcha
  • Decaptcher

The tesseract library solve some examples simples in captcha.

like image 23
iNktown Avatar answered Nov 15 '22 08:11

iNktown


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/

like image 35
malepati varaprasad Avatar answered Nov 15 '22 09:11

malepati varaprasad