Wednesday, 3 July 2013

Automating(Breaking) captcha using Selenium Webdriver


Usually most of the companies either use their own captchas or one of the third party captchas(GooglejQuery plugins) in the user registration page of their sites .So these pages can't be automated fully.Infact Captcha itself is implemented to prevent automation. As per official captcha site

A CAPTCHA is a program that  protects  websites against bots  by generating and grading tests that humans can pass but current computer programs cannot.

Captchas are not brakeable but there are some third party captchas that can be breakable and one of the example for it is "jQuery Real Person" captcha . Here is the documentation  :)

Vamshi Kurra- Real Person Captcha


Here is the sample code to brake the "jQuery Real Person" Captcha using Selenium WebDriver.

  1. import org.openqa.selenium.By;  
  2. import org.openqa.selenium.JavascriptExecutor;  
  3. import org.openqa.selenium.WebDriver;  
  4. import org.openqa.selenium.firefox.FirefoxDriver;  
  5. import org.testng.annotations.BeforeTest;  
  6. import org.testng.annotations.Test;  
  7.   
  8. public class captchaAutomtion {   
  9.    
  10.  WebDriver driver;  
  11.    
  12.  @BeforeTest  
  13.  public void start(){  
  14.   driver = new FirefoxDriver();  
  15.  }  
  16.    
  17.  @Test  
  18.  public void Test(){   
  19.   //Loading jQuery Real Person Captcha demonstration page  
  20.   driver.get("http://keith-wood.name/realPerson.html");  
  21.   JavascriptExecutor js = (JavascriptExecutor) driver;  
  22.   //Setting the captcha values  
  23.   js.executeScript("document.getElementsByName('defaultRealHash')[0].setAttribute('value', '-897204064')");  
  24.   driver.findElement(By.name("defaultReal")).sendKeys("QNXCUL");  
  25.   //Submit the form  
  26.   driver.findElement(By.xpath(".//*[@id='default']/form/p[2]/input")).submit();   
  27.  }  
  28.   
  29. }  

Do share some of the captcha plugins that can be breakable with me :P

3 comments:

  1. driver.findElement(By.name("defaultReal")).sendKeys("QNXCUL"); here u are entering your own values it is not the case for captcha

    ReplyDelete
  2. Can you brief some more about '-897204064'? How we get this number ?

    ReplyDelete
  3. Can you brief some more about '-897204064'? How we get this number ?

    ReplyDelete

Angular JS Protractor Installation process - Tutorial Part 1

                     Protractor, formally known as E2E testing framework, is an open source functional automation framework designed spe...