Elements of JMeter


Below figure represents most widely used components of JMeter called as elements:

JMeterTutorial

Studying all of the JMeter Components will be confusing so I am covering only the most important JMeter elements:
  1. Thread Group
  2. Samplers
  3. Configuration
  4. Listeners

Thread Group

Event By ThoughtWorks : Beyond Automation - Continuous Integration : Gurgaon



This is just to inform you about the upcoming event on Beyond Automation - Continuous Integration. This event is being organised by ThoughtWorks on Saturday 06 Dec, 2014 09:00 AM at:

ThoughtWorks Technologies (India) Pvt Ltd. 

6th Floor, 
Tower Building No. 14
DLF Cyber City Phase III
Gurgaon-122002, Haryana

Beyond Automation - Continuous Integration’ will be an interactive workshop which aims to challenge your skill set to a level beyond automation. Continuous delivery has become the mantra in the agile world to get the automation test results feedback at the earliest in a short span of time. When there are frequent code pushes in a distributed or non-distributed team, it becomes important to have your set of tests with each build as every time doing it manually is a difficult task.

The topics covered will be appropriate for testers with basic knowledge of selenium. Also do bring your own Windows machines having Java and Selenium setup.

For registration, do visit below link:

If you face any issue, you can contact me by completing the Contact Us form.

JMeter Tutorial : Introduction to JMeter


This is just an introduction to JMeter. Below are some points covered in this video:

- How to install and configure JMeter?
- Why JMeter and Features of JMeter
- History of JMeter
- Parameters of JMeter
- Introduction to Sampler, Threads, Listeners, Controllers, Timer, Pre-Processor, Post-Processor, Test Plan, Work Bench etc






Continuous Integration Tool : Jenkins + Selenium + TestNG


A complete tutorial for Continuous Integration Tool : Jenkins

What is Continuous Integration?

“Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily - leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration
errors as quickly as possible” – Martin Fowler

CI - Workflow














CI - Benefits

  • — Immediate bug detection
  •  No integration step in the lifecycle
  •  A deployable system at any given point
  • — Record of evolution of the project

Jenkins

About Jenkins

  • Branched from Hudson
  • —Java based Continuous Build System
  • Runs in servlet container
  • Glassfish, Tomcat
  • Supported by over 400 plugins
    • SCM, Testing, Notifications, Reporting, Artifact Saving, Triggers, External Integration
  • Under development since 2005
  • http://jenkins-ci.org/

Jenkins - History


  • 2005 - Hudson was first release by Kohsuke Kawaguchi of Sun Microsystems
  • 2010 – Oracle bought Sun Microsystems
    • Due to a naming dispute, Hudson was renamed to Jenkins
    • Oracle continued development of Hudson (as a branch of the original)

What can Jenkins do?


  • Generate test reports
  • —Integrate with many different Version Control Systems
  • Push to various artifact repositories
  • Deploys directly to production or test environments
  • Notify stakeholders of build status 
  • …and much more

Step By Step : Process to Install and Configure Jenkins With your Script.

1) Download Jenkins by clicking here:












2) Keep the downloaded Jenkins.war file where your project is placed. For Example:











3) Open Command Prompt and go to the project path. Like:






4) After going to that path, write java -jar jenkins.war and press Enter.

How to take Screenshots if Test Case fails?


One basic question which comes in everyone's mind is : What happens if test case fails? Where was the error in script and How can we capture it?

So, the solutions is always (at least in most of the cases) to take screenshots of webpage when the test run fails.

With one look at the screenshot we can get an idea of where exactly the script got failed. Moreover reading screenshot is easier compare to reading 100's of console errors

To get screenshot on test failure, we should put the entire code in try-catch block. In the catch block we should paste the screenshot code:

public class TakeScreenshot {
 
   WebDriver driver;
 
 @BeforeTest
 public void start(){
  driver = new FirefoxDriver();
 }


Run a Bat File with Java Program


Sample JAVA Code:

public class RunBat {

public static void main(String[] args) throws IOException, InterruptedException{

Runtime runtime = Runtime.getRuntime();
Process process = runtime.exec("cmd /c F:\\bb.bat");
process.waitFor();
}
}

How to handle Authentication PopUp using Selenium?

Sometime we have to automate websites which shows authentication Pop Up like mentioned below:











In order to automate this PopUp, we will pass UserId and Password via URL:

http://username:password@anytestwebsite.com

Java Script:

String URL = "http://" + username + ":" + password + "@" + anytestwebsite.com;
driver.get(URL);
Alert alert = driver.switchTo().alert();
alert.accept();

Database Connection in Selenium


  • Below is the source code to connect your MySQL database with Selenium :
Class.forName("com.mysql.jdbc.Driver");
Connection con = (Connection) DriverManager.getConnection ("jdbc:mysql://localhost:3306/demo","username","password");
Statement stmt = (Statement) con.createStatement();
// Below statement we use for executing sql queries.
stmt.executeQuery("Select * from dbtable");

In order to connect, you will need to add one jar file which you can download by clicking here

  • To connect Oracle database with Selenium, write below code:
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection con =
DriverManager.getConnection("jdbc:oracle:thin:@localhost: 
1521:orcl","username","password");
Statement stmt = con.createStatement();
stmt.executeQuery("Select * from dbtable");

In order to connect, you will need to add one jar file which you can download by clicking here

Selenium Webdriver Architecture


This diagram is just to show how Selenium Webdriver works. If anyone asks for Selenium Webdriver architecture then just need to design the below diagram and explain it. I share this as it is one of the most frequently asked Selenium Question

Selenium Architecture
Selenium Webdriver Architecture

Selenium Remote Control Architecture


This diagram is just to show how Selenium Remote Control works. If anyone asks for Selenium RC architecture then just need to design the below diagram and explain it. I share this as it is one of the most frequently asked Selenium Question


Selenium RC Architecture
Selenium Remote Control Architecture

Alert handling in Selenium


public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
String Url = "http://sislands.com/coin70/week1/dialogbox.htm";
driver.get(Url);
WebElement alert = driver.findElement(By.xpath("///div[1]/center/table/tbody/tr/td/form[1]/p/input"));
alert.click();
Alert popup = driver.switchTo().alert();
System.out.println(popup.getText());
popup.accept();
Thread.sleep(3000);
driver.close();

}

Pick Date From a Calendar in Selenium



public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
driver.get("http://jqueryui.com/datepicker/");
driver.manage().window().maximize();
driver.switchTo().frame(0);
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
driver.findElement(By.xpath("//*[@id='datepicker']")).click();
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
driver.findElement(By.xpath("//*[@id='ui-datepicker-div']/div/a[2]/span")).click();
List column = driver.findElements(By.tagName("td"));
for (WebElement j : column)
{
if (j.getText().contains("13")){
j.findElement(By.linkText("13")).click();
break;
}
}
Thread.sleep(5000);
}

How to write dynamic Xpath to identify elements on Webpage?


We always have concerns about writing Dynamic Xpath. So, I've listed below some ways to write xpath with example. If you face any problem, Contact Us:

1) Based on location
2) Using Single Attributes
3) Using Multiple Attributes
4) Using functions


All examples are based on following HTML Code:

input class="search-field" name="s" placeholder="Search …" title="Search for:" type="search" value=""

Run your script in Internet Explorer (IE)


 public static void main(String[] args) throws InterruptedException { DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer(); ieCapabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true); System.setProperty("webdriver.ie.driver", "C:/IEDriverServer.exe"); WebDriver driver = new InternetExplorerDriver(ieCapabilities); driver.get("http://google.com"); Thread.sleep(5000); driver.quit(); }

- Download IE Driver by Clicking Here

How to handle Cookies using Selenium Webdriver?



  • Sometimes, we face issues because of cookies session created by Selenium scripts and we have to delete them using Selenium Webdriver. So, here is the code:

public class Cookies
{
    public static void main(String[] args) 
    {
        WebDriver driver=new FirefoxDriver();
        driver.get("http://in.quikr.com/");
        
        Set cookies=driver.manage().getCookies();
        
        //To fetch out the number of cookies used by this site
        System.out.println("Number of cookies in this site "+cookies.size());
        
     //Using advanced For Loop
        for(Cookie cookie:cookies)
        {
            System.out.println(cookie.getName()+" "+cookie.getValue());
            
            //This will delete cookie By Name
            driver.manage().deleteCookieNamed(cookie.getName());
            
             }
         //This will delete all cookies.
        driver.manage().deleteAllCookies();
           } }

For any query, ContactUs

Mouse Hover in selenium



public static void main(String[] args) throws InterruptedException {

WebDriver driver = new FirefoxDriver();
driver.get("http://www.timeanddate.com/");
driver.manage().window().maximize();
WebElement menu = driver.findElement(By.xpath("//*[@id='nav']/ul/li[3]/a"));
Actions action = new Actions(driver);
action.moveToElement(menu).perform();
WebElement submenu = driver.findElement(By.xpath("//*[@id='nav']/ul/li[3]/ul/li[4]/a"));
action.moveToElement(submenu).click().perform();

Thread.sleep(5000);
driver.close();
}

For any queries, ContactUs

Get all links of a Webpage using Selenium


How to test links of any website?

public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.co.in/");
List links = driver.findElements(By.tagName("a"));
System.out.println(links.size());    // to check the number of links present at webpage
for (int i = 1; i {
System.out.println(links.get(i).getText());
}
}

How to handle iFrames in Selenium?


A basic example of handling frames at www.espncricinfo.com

import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Abc
{
public static void main(String args[])
{
WebDriver driver=new FirefoxDriver();
driver.get("http://www.cricinfo.com/");
driver.manage().timeouts().implicitlyWait(3000, TimeUnit.MILLISECONDS);
driver.findElement(By.linkText("Countries")).click();
driver.switchTo().frame(driver.findElement(By.xpath("//*[@id='ciHomeContentrhs']/iframe")));
driver.findElement(By.linkText("Cricinfo")).click();
}
}

How to handle multiple windows in Selenium?


Example of handling Multiple Windows in Selenium:

public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
WebDriver driver = new FirefoxDriver();
driver.get("https://www.abc.com/");
driver.manage().window().maximize();
String Window1 = driver.getWindowHandle();
driver.findElement(By.linkText("Contact us Now")).click();
for (String Window2 : driver.getWindowHandles())
{
driver.switchTo().window(Window2);
}
driver.findElement(By.xpath("//*[@id='bigin']")).sendKeys("abcde");
Thread.sleep(5000);
driver.close();
driver.switchTo().window(Window1);
driver.getTitle();
Thread.sleep(3000);
driver.close();
}

For more info, Contact Us

How to handle Select in Selenium


Example of using Select in Selenium 

public static void main(String[] args) throws InterruptedException {
WebDriver driver = new FirefoxDriver();
driver.get("https://www.mobikwik.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@id='mobile_number']")).sendKeys("9910979218");
driver.findElement(By.xpath("//*[@id='mobile_amount']")).sendKeys("10");
WebElement operator = driver.findElement(By.xpath("//*[@id='mobile_operator']"));
Select option = new Select(operator);
option.selectByVisibleText("Idea");
Thread.sleep(5000);
driver.close();
}

How to register in Facebook?


Below is the code to make an account on Facebook using Selenium Wedriver:

public class FacebookRegistration {

public static void main(String[]args)
{
WebDriver driver = new FirefoxDriver();
driver.get("https://www.facebook.com/");
driver.manage().window().maximize();
driver.findElement(By.xpath("//*[@value='First Name']")).sendKeys("raj");
driver.findElement(By.xpath("//*[@value='Last Name']")).sendKeys("raja");
driver.findElement(By.xpath("//*[@value='Your email address']")).sendKeys("raja@mail.com");
driver.findElement(By.xpath("//*[@value='Re-enter email address']")).sendKeys("raja@mail.com");
driver.findElement(By.xpath("//*[@value='New Password']")).sendKeys("A123a!");
new Select(driver.findElement(By.xpath("//*[@name='birthday_day']"))).selectByValue("1");
new Select(driver.findElement(By.xpath("//*[@id='month']"))).selectByValue("2");
new Select(driver.findElement(By.xpath("//*[@id='year']"))).selectByValue("1987");
driver.findElement(By.xpath("//*[@id='u_0_g']/span[1]/label")).click();
driver.findElement(By.xpath("//*[@id='u_0_i']")).click();
}
}

Selenium New Version i.e. 2.42.0


Selenium new version is available i.e 2.42.0 , please download it from below link and update your libraries so that you will not face any compilation or any other version related issue:

http://goo.gl/l3AasO

To stay update, just like my Facebook page

What is the difference between Xpath and DOM (Document Object Model)?


This is the question asked in most of the interviews of Selenium:

DOM: 

The Document Object Model (DOM) is a cross-platform and language-independent convention for representing and interacting with objects in HTML, XHTML and XML documents. Objects in the DOM tree may be addressed and manipulated by using methods on the objects.

Ex: var element=document.getElementById("intro");

XPATH: 

XPath, the XML Path Language, is a query language for selecting nodes from an XML document. In addition, XPath may be used to compute values (e.g., strings, numbers, or Boolean values) from the content of an XML document.

Ex: //input[@id=”xxx”]

Difference Between Implicit Wait and Explicit Wait


Implicit Wait – 

An implicit wait is to tell WebDriver to stop the DOM for a certain amount of time. The default setting is 0. 

Syntax – driver.manage().timeouts().Implicitly Wait(10, TimeUnit.SECONDS); 

Explicit Wait - 

What is the difference between absolute and relative Xpath?


Absolute Xpath : 

1) start selection from the document node
2) Starts with //
3) e.g. “/html/body/p” matches all the paragraph elements

Google Search Box : /html/body/div[1]/div[2]/div[1]/div[1]/div[3]/div/div/div/form/fieldset[2]/div/div/div

Relative Xpath  : 

1) start selection matching anywhere in the document
2) Starts with /
3) e.g. “//p” matches all the paragraph elements starts with p

Google Search Box : //*[@id='gbqfqwb']

TestNG Error Codes


We write automation framework using TestNG and when we run it we get errors sometimes. So, it becomes important for us to know about error messages. 

I have put some of the error messages that we get when we go wrong and execute TestNG XML file:

1.If two tests are having the same name then we see below error

at org.testng.TestNG.checkTestNames(TestNG.java:981)
at org.testng.TestNG.sanityCheck(TestNG.java:970)
at org.testng.TestNG.run(TestNG.java:1002)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:109)

2.If the testname doesnot enclosed in double quotes("") then we get below error


Launched a tutorial on JMeter


This is just an introduction to JMeter. Below are some points covered in this video:

- How to install and configure JMeter?
- Why JMeter and Features of JMeter
- History of JMeter
- Parameters of JMeter
- Introduction to Sampler, Threads, Listeners, Controllers, Timer, Pre-Processor, Post-Processor, Test Plan, Work Bench etc



How to Zoom In and Zoom Out in Website

In case, you want to zoom in and out in any website using Selenium. You can follow below commands:

To Zoom In:

WebElement Sel= driver.findElement(By.tagName("html"));
sel.sendKeys(Keys.chord(Keys.CONTROL, Keys.ADD));

To Zoom Out to normal page, use below command:

html.sel(Keys.chord(Keys.CONTROL, "0"));

This can be useful when you need to pin point something while showing your automation framework to any user. 

How to get data from an Excel sheet?


If you're looking how to pick username and passwords or any data from an excel sheet then below steps will help you out:

1) Download J-Excel jar (What is J-Excel), you can get the path to download J-Excel jar by clicking here
2) Now, add this jar to your build path. You can look for the steps here.
3) Create a new class and add below code:

public class Excel {
static Sheet s ;
 public static void main(String[] args) throws BiffException, IOException {
  
FileInputStream fis = new FileInputStream("C:\\Users\\DELL\\Desktop\\r.xls");
Workbook w = Workbook.getWorkbook(fis);
s = w.getSheet(0);

Generate Random Data


In your scripts, you always want to generate random data to automate SignUp forms, below is code to generate random password. If you need script to generate data to complete forms like available here, do write an email to me:

--------------

public static void main(String[] args) {

//can put any array below depending on requirement
String array = "abcde1234567890~!@#$%^&*()_+";

//calculates its length
int i = array.length();

 //password with length 10
for (int j =0; j<=10; j++)

//randomly picking up 10 characters
{
 int k = (int)(Math.random()*i);
char pass = array.charAt(k);
 System.out.print(pass);
 }
 }

Interview Questions and Answers on Automation Testing

Click on the questions below to get the answers


1) What is Automation ?

Answer: In general, it is the process of implementing particular work automatically by using a machine, to reduce the need of human work in the production of goods and services.
2) What is meant by Automation in software testing ?

Answer: It is a process of testing an application(executing the tests, comparing expected and actual results under some controlled conditions and generating the reports) automatically by using a 'Tool' to reduce the need of human effort. This tool may be Selenium / QTP / RFT / SilkTest etc.
3) Why do we need automation in software testing ?

Answer: Humans can do mistakes. If a work is repetitive then we may skip some work intentionally or unintentionally due to time pressure, boring task, etc. In order to overcome these problems 'automation testing' has been introduced to reduce manual task, to save cost and time, to improve accuracy, to perform repetitive execution of tests, to customize defect reporting etc. and hence automation is needed, as it replaces human with great features.
4) Which type of testing can be Automated ?

Answer: We can automate Regression testing, Functional testing, Stress testing, Performance testing, Load testing, Smoke testing, Compatibility testing, Data-Driven testing etc.
5) When to do automation testing ?

Answer: It is not always advantageous to automate test cases. We can do automation:
- When the application is stable.
- For long term projects.
- When you have lot of regression work.
- When the scenario is easily debuggable.
6) What are the advantages and disadvantages of Automation Testing ?
Answer:

Advantages :
- Reduces human resources.
- Using an automation tool, test scripts can be executed faster when compared to manual execution and hence saves time.
- Repeatable execution of tests may lead to make mistakes when it is done manually but when we automate the same task, accuracy will be improved.
- Test cases can be reused in various versions of software which saves time and cost.

Disadvantages:
- Unemployment rate increases as machine replaces human.
- It is not so easy to write automation test scripts, it requires skilled and experienced resources.
- We cannot automate everything as it is advantageous only for repeatable and reusable test cases.
- Initial cost for automation is very high unless it is open source.
- Debugging skills should be high otherwise its effect will be dangerous (mainly it kills time, so, we cannot reach dead-line).

7) Name some test automation tools?
Answer:

- Selenium (Open Source)
- HP QuickTest Professional (Commercial)
- IBM Rational Functional Tester (Commercial)
- HP WinRunner (Commercial)
- SilkTest (Commercial)
- HTTP Test Tool (Open Source)
- WATIR (Open Source)
- Maveryx (Open Source)
- eggPlant (Commercial)

8) What kind of tests should NOT be automated?
Answer:

- Automating tests that only need to be executed once doesn't make sense.
- Tests without predictable results – test automation should give us confidence in the results of the tests. If there are intermittent failures then the tests cannot be reliable.
- Tests that need to be verified visually
- Tests that need to be executed quickly. At first, writing an automated test takes longer. If we want a quick check, we should test it manually however, if that test is a good one which should be run regularly, then it should be automated in time
- Usability Testing – at times it becomes impossible to perform testing by automation as the computer cannot efficiently judge if the system is of any use to its users.

Difference between Jexcel and Apache POI


JExcel

Apache POI

  • It doesn’t support Excel 2007 and Xlsx format. It supports only Excel 2003 and .Xls format

  • It supports both

  • JXL doesn’t support Conditional formatting

  • It supports

  • JXL API was last updated in 2009

  • Apache POI is actively maintained

  • It doesn't support rich text formatting

  • Apache POI supports it

  • It has very less documents and examples as compare to Apache POI

  • It has extensive set of documents and examples


You can download Apache POI jar by clicking here
You can download JExcel jars by clicking here

Example of JExcel Click Here

Access Modifiers in Java


We always use Public, Private, Protected in our Selenium scripts. Before using these, we should know how and where to use these access modifiers. Here is the table showing where we can call these modifiers:

Access Modifier
within class
within package
outside package by 
subclass only
outside 
package
Private
Y
N
N
N
Default
Y
Y
N
N
Protected
Y
Y
Y
N
Public
Y
Y
Y
Y


Basic Selenium Commands


Below are some basic commands of selenium which you can try and use while writing your script for automation of any website. If you face any problem, you can raise your query by completing the form available at Contact Us page:

  1. driver.get("http://www.google.com"); To open an application
  2. driver.findElement(By.id("passwd-id")); Finding Element using Id
  3. driver.findElement(By.name("passwd")); Finding Element using Name
  4. driver.findElement(By.xpath("//input[@id=’passwd-id’]")); Finding Element using Xpath
  5. element.sendKeys("some text"); To type some data
  6. element.clear(); clear thecontents of a text field or textarea
  7. driver.findElement(By.xpath("//select")); Selecting the value
  8. select.findElements(By.tagName("option")); Selecting the value
  9. select.deselectAll(); This will deselect all OPTIONs from the first SELECT on the page
  10. select.selectByVisibleText("Edam"); select the OPTION withthe displayed text of “Edam”
  11. findElement(By.id("submit")).click(); To click on Any button/Link
  12. driver.switchTo().window("windowName"); Moving from one window to another window
  13. driver.switchTo().frame("frameName"); swing from frame to frame (or into iframes)
  14. driver.switchTo().frame("frameName.0.child"); to access subframes by separating the path with a dot, and you can specify the frame by itsindex too.
  15. driver.switchTo().alert(); Handling Alerts
  16. driver.navigate().to("http://www.example.com"); To Navigate Paeticular URL
  17. driver.navigate().forward(); To Navigate Forward
  18. driver.navigate().back(); To Navigate Backword
  19. driver.close(); Closes the current window
  20. driver.quit(); Quits the driver and closes every associated window.
  21. driver.switch_to_alert(); Switches focus to an alert on the page.
  22. driver.refresh(); Refreshes the current page.
  23. webdriver.manage().window().setPosition(new Point(-2000, 0); to minimize browser window

How to setup Classpath for Java in Windows 7?



We all know the importance of CLASSPATH for Java. Setting PATH/CLASSPATH is very easy if we have the correct steps. I've listed down the steps which will help you to set CLASSPATH/PATH for Java:
 
Step 1: Download Java or JDK from the following URL according to your computer configuration:
Step 2: Install it by click on setup.exe and following the steps.
Step 3: By default JDK installs at "C:\Program Files\Java\jdkxxx.xx" location only. Unless we change the location at the time of installation.
Step 4: Go to JDK installed location, open bin folder available at the location. Now, copy the path.
Step 5: Right-click on My Computer icon available at your desktop and select Properties.
Step 6: Now, click on Advanced System Settings and click on Advanced tab from the dialog box opened
Step 7: Click on Environment Variables and then System Variables.

Step 8: Edit path and add the copied bin (which we did in Step 4) in that. Below are some images to help you:



Step 9: Click on OK of Environment Variables window and System Properties window.
Step 10: To verify whether Classpath or path of java is set up correctly or not.

Open Command Prompt and enter java -version. You'll find a statement like mentioned below:

java version "1.7.0_45"
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)

Prerequisites to Start Learning Selenium Webdriver


You will need the following to start using Selenium WebDriver or in other words you can say prerequisites required to setup Selenium Webdriver??


  • Java Development Kit (JDK) ( To download it, click here)
  • Eclipse IDE - (To download it, click here)
  • Jar Files (Java Client Driver) - (To download it, click here)

What is HTMLUnitDriver?


HTMLUnitDriver is fastest (50% faster than Firefox), lightweight, platform independent. However, we don't use it. We always prefer to use Firefox, Chrome, IE but not HTMLUnitDriver

Do you know why?? 

Here is the answer:

How to Login and Logout in Gmail

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Openbrowser
{
public static void main(String args[]) throws InterruptedException
{
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get("http://gmail.com/");
driver.findElement(By.id("Email")).sendKeys("raghav@mobikwik.com");
driver.findElement(By.id("Passwd")).sendKeys("9910979218");
driver.findElement(By.id("signIn")).click();
Thread.sleep(4000);
driver.findElement(By.xpath("//*[@id='gb']/div[1]/div[1]/div[2]/div[5]/div[1]/a/span")).click();
driver.findElement(By.id("gb_71")).click();
}
}