Am trying to automate button properties,but error is this java.lang.NullPointerException,please help me below is the code

Raghu . June 13, 2013
package com.property;



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


public class Gbuttonproperty {
	
	
	private WebDriver driver;
	private String buttonText=null;
	private int buttonhight=0;
	
	
	public String buttontext(String locator,String Value) 
	{
	
		if(locator=="xpath")
		{
		 buttonText=driver.findElement(By.xpath(Value)).getText();
		 return buttonText;
		
		}
		else if(locator == "id")
		{
		     buttonText = this.driver.findElement(By.id(Value)).getText();
			return buttonText;
		}
		else if(locator=="name"){
			String buttonText = this.driver.findElement(By.name(Value)).getText();
			return buttonText;
		}
		else if(locator=="classname"){
			String buttonText = this.driver.findElement(By.className(Value)).getText();
			return buttonText;
		}
		else if(locator=="cssSelector"){
			String buttonText =this.driver.findElement(By.cssSelector(Value)).getText();
			return buttonText;
		}
		
		return null;
	}
	public int buttonhight(String locator,String Value){
	
		if(locator== "xpath")
		{
		System.out.println("hello");
		int buttonhight = driver.findElement(By.xpath(Value)).getSize().getHeight();
	    return buttonhight;
		}
		else if(locator == "id")
		{
			int buttonhight =this.driver.findElement(By.id(Value)).getSize().height;
			return buttonhight;
		}
		else if(locator=="name"){
			int buttonhight = this.driver.findElement(By.name(Value)).getSize().getHeight();
			return buttonhight;
		}
		else if(locator=="classname"){
			int buttonhight = this.driver.findElement(By.className(Value)).getSize().getHeight();
			return buttonhight;
		}
		else if(locator=="cssSelector"){
			int buttonhight = this.driver.findElement(By.cssSelector(Value)).getSize().getHeight();
			return buttonhight;
		}
		return 0;
	}

}
package com.properies;
import com.property.Gbuttonproperty;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;



public class Gbutton {
    private WebDriver driver;
	private String baseUrl;
	private Gbuttonproperty buttonproperty;
	//Gbuttonproperty b = new Gbuttonproperty();
	
	 @BeforeMethod
	  public void start() throws Exception {
		   baseUrl = "https://www.google.com/";
		   driver = new FirefoxDriver();
		   
	   }
	   @Test  
	   public void button(){
		   driver.get(baseUrl );
		   Gbuttonproperty b=new Gbuttonproperty();
		   
		   b.buttonhight("xpath", "//*[@id='gbqfba']");
		   b=null;
		   b.buttontext("xpath","id('gbqfba')");
		   b=null;
		   
		  
		   }
	   @AfterMethod
		  public void tearDown() throws Exception {
		    driver.quit();
		   
		  }
	   
}

1 answer

0 votes
Raghu . June 13, 2013

plz provide answer to this question

Suggest an answer

Log in or Sign up to answer