Getting Null pointer Exception, help me to resolve | Selenium Training|Java|WebDriver|TestNG|Frameworks|Videos
15% Learning Discount Avail now

Selenium Training Forum

Getting Null pointer Exception, help me to resolve

V
Vanitha hegde Post on 07/11/2019

package day4;

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 sample_script_xpath {

public static void main(String[] args) {
String browser="Mozilla";
WebDriver driver = null ;
if(driver.equals("Mozilla"))
driver=new FirefoxDriver();
else if(driver.equals("Chrome"))
driver=new ChromeDriver();
driver.get("https://login.salesforce.com/?locale=in");
WebElement UserName=driver.findElement(By.id("username"));
UserName.sendKeys("SampleUser");
}

}

 

Error :

Exception in thread "main" java.lang.NullPointerException
at day4.sample_script_xpath.main(sample_script_xpath.java:14)

S

Instructor

Support Team Reply on 08/11/2019

if(driver.equals("Mozilla"))

 

should be

 

if(browser.equals("Mozilla"))