Thursday, May 29, 2014

Captcha which could be automated.


1- Captcha which could be automated-

This is the example from-  http://www.indianrail.gov.in/pnr_Enq.html 




import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class CaptchaAutomated {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.indianrail.gov.in/pnr_Enq.html");
        String captchaValue = driver.findElement(By.xpath("//span[@id='txtCaptchaDiv']")).getText();  //this will read the captcha
        System.out.println(captchaValue);
        driver.findElement(By.xpath("//input[@id='txtInput']")).sendKeys(captchaValue);
    }
}

Output-  This program will read the captcha and will enter the value of captcha in the Enter Captcha box.




2- Captcha which could not be automated-

This is an example from - https://signup.live.com/signup.aspx
Such kind of captcha can not be automated.

11 comments:

  1. How to automate this captcha

    http://register.rediff.com/register/register.php?FormName=user_details

    ReplyDelete
    Replies
    1. i don't think , that this could be automated because its an image and text value is not anywhere there in the html code so we can't get the text value of this.

      I already given example of similar type, you can refer above in the post. Thanks.!!

      Delete
  2. Hi Sanjay, nice blog very informative and helpful. Thanks a lot .
    In this captcha example 2 looks like there is typo "Such kind of captcha can be automated." it should be cannot be automated

    ReplyDelete
    Replies
    1. Thanks Hari for pointing out, i have changed now. Thanks!!

      Delete
    2. Hi All,

      I want to automate web Application, But it contains captcha.
      The Xpath is:
      .

      can i automate the captcha by using any one of the above attributes.
      Please help me.

      Delete
  3. I believe this is not working as expected buddy. Could you please recheck. I tried the exact program but not giving me the captcha value.

    ReplyDelete
  4. Hi Sanjay, nice blog..Thank you very much..
    Captcha is an image file..how can u convert it into text..and also it is dyamic..it will change the value every time..

    ReplyDelete
    Replies
    1. as mentioned in blog, if value of captcha is present in dom then only you can automate it. Or if you can get the value of captcha from your dev then you can automate else not.

      Delete
  5. im using win7 32-bit, jst now i installed jdk, Eclipse(Mars), and added selenium webdriver jar file in build path to a new proj...
    but when i running a program..it is jst opening FF browser., not going to the output webpage...show me a solution to it..

    ReplyDelete
    Replies
    1. downgrade your firefox version to 45.0.
      https://ftp.mozilla.org/pub/firefox/releases/45.0/mac/en-US/
      There is some issue with the firefox version 47 and 48.

      Delete
    2. Thank U Sanjay..I will try

      Delete