Search code examples
eclipsetestingselenium-webdriverfirefox-marionette

I am getting error "java.lang.NullPointerException"


I am using selenium Webdriver for the testing web application. I am using marioette driver for the same as I am havin firefox 48.0 since yusing the same the web page gets open however I am not able to put the values in the text box it gives the error " java.lang.NullPointerException" I have written code

@BeforeTest
      public void setUp() throws Exception {
         System.setProperty("webdriver.gecko.driver", "D:\\ashwini\\geckodriver.exe");

          driver= new MarionetteDriver();

        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
      }

@Test
      public void testAddAccount() throws Exception {
        driver.get("http://qa.luna.wexeurope.com/CPCardWeb/login.htm?programme=CPYCGB");

        driver.findElement(By.id("username")).clear();
        driver.findElement(By.id("username")).sendKeys("cp_admin");
}


@AfterTest
      public void teardown()
      {
          driver.quit();
      }

Output is:

1472448949884   Marionette  INFO    sendAsync 3744f8a9-772e-42fe-8c85-6f9964888fb1
FAILED: testAddAccount
java.lang.NullPointerException
at Add_Account.testAddAccount(Add_Account.java:36)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)

I have checked the same it gives null values in sendkeys. However instead of by.id I have used other options like name, xpath, css selector for the same it gives the error only. Value is still not inserted in the text box

Line no 36 is driver.findElement(By.id("username")).clear(); driver.findElement(By.id("username")).sendKeys("cp_admin");

I have debug that as you said, Yes it passes the null value to the element that's why it throws null pointer exception. so please let me know to solve this. as I have tried to pass values using the id, name, xpath, css selecter. same error is displayed. so could u please help me?


Solution

  • issue is resolved by removing unwanted jar from the referenced library