My Thoughts: November 2012

Monday, November 26

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.

import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class captchaAutomtion { 
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){
  driver = new FirefoxDriver();
 }
 
 @Test
 public void Test(){ 
  //Loading jQuery Real Person Captcha demonstration page
  driver.get("http://keith-wood.name/realPerson.html");
  JavascriptExecutor js = (JavascriptExecutor) driver;
  //Setting the captcha values
  js.executeScript("document.getElementsByName('defaultRealHash')[0].setAttribute('value', '-897204064')");
  driver.findElement(By.name("defaultReal")).sendKeys("QNXCUL");
  //Submit the form
  driver.findElement(By.xpath(".//*[@id='default']/form/p[2]/input")).submit(); 
 }

}

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

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms

 I am using selenium 2.24 jar files.But today , I got below errors when I ran one of my sample script.
org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms. Firefox console output:
*** LOG addons.manager: Application has been upgraded
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\vkurra\AppData\Local\Temp\anonymous4553384920216924839webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi-utils: Opening database
*** LOG addons.xpi-utils: Creating database schema
*** LOG addons.xpi: New add-on fxdriver@googlecode.com installed in app-profile
*** LOG addons.xpi: New add-on {972ce4c6-7e08-4474-a285-3208198ce6fd} installed in app-global
*** LOG addons.xpi: Updating database with changes to installed add-ons
*** LOG addons.xpi-utils: Updating add-on states
*** LOG addons.xpi-utils: Writing add-ons list
*** LOG addons.xpi: shutdown
*** LOG addons.xpi-utils: shutdown
*** LOG addons.xpi-utils: Database closed
*** LOG addons.xpi: startup
*** LOG addons.xpi: Skipping unavailable install location app-system-local
*** LOG addons.xpi: Skipping unavailable install location app-system-share
*** LOG addons.xpi: Ignoring file entry whose name is not a valid add-on ID: C:\Users\vkurra\AppData\Local\Temp\anonymous4553384920216924839webdriver-profile\extensions\webdriver-staging
*** LOG addons.xpi: checkForChanges
*** LOG addons.xpi: No changes found


Immidiate thing I have done is , selenium jars updation. I have downloaded latest selenium 2.25 jars and added them to my project buildpath. Now things are going smooth :)

Saturday, November 17

5 different ways to refresh a webpage using Selenium Webdriver

Here are the 5 different ways, using which we can refresh a webpage.There might be even more :)

There is no special extra coding. I have just used the existing functions in different ways to get it work. Here they are :

1.Using sendKeys.Keys method
driver.get("https://accounts.google.com/SignUp");
driver.findElement(By.id("firstname-placeholder")).sendKeys(Keys.F5);

2.Using navigate.refresh()  method
driver.get("https://accounts.google.com/SignUp");  
driver.navigate().refresh();

3.Using navigate.to() method
driver.get("https://accounts.google.com/SignUp");  
driver.navigate().to(driver.getCurrentUrl());

4.Using get() method
driver.get("https://accounts.google.com/SignUp");  
driver.get(driver.getCurrentUrl());

5.Using sendKeys() method
driver.get("https://accounts.google.com/SignUp"); 
driver.findElement(By.id("firstname-placeholder")).sendKeys("\uE035");

See you in next post.

Have a great weekend..!!

Tuesday, November 13

Happy Diwali all..!!


May all your happiness light up and sorrows burn out. 
♥  Happy Diwali all..!!  





Monday, November 12

Null point exception while running webdriver script


Sometimes simple mistakes will take lot of time in debugging . I can bet on it :P
Today while runing a sample script I got errors like below :

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)

Here is the script with syntax error:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AutoComplete {
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){
 WebDriver driver = new FirefoxDriver();
 }
 
 @Test
 public void AutoComplete()
 {
 driver.get("http://mythoughts.co.in/");
 driver.manage().window().maximize();
 }

}


I just overlooked the above script and thought everything is fine. But the issue got fixed when I remove the "WebDriver" statement from the line 13 and script ran successfully.

Here is the script which ran successfully.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class AutoComplete {
 
 WebDriver driver;
 
 @BeforeTest
 public void start(){
 driver = new FirefoxDriver();
 }
 
 @Test
 public void AutoComplete()
 {
 driver.get("http://mythoughts.co.in/");
 driver.manage().window().maximize();
 }

}