How to automate captcha using Selenium Webdriver? [closed]

笑着哭i 提交于 2021-01-27 04:36:15

问题


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


回答1:


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




回答2:


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

  • DeathByCaptcha
  • 2Captcha
  • AntiCaptcha
  • Decaptcher

The tesseract library solve some examples simples in captcha.




回答3:


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/



来源:https://stackoverflow.com/questions/35859974/how-to-automate-captcha-using-selenium-webdriver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!