0

package automate;

import java.util.List; import java.util.concurrent.TimeUnit;

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

public class FunctionalTest {

WebDriver driver;

@BeforeTest

public void browserConfiguration() {

System.setProperty("webdriver.gecko.driver","C://Users//Admin//workspace//Guru99Test//drivers//geckodriver.exe");

WebDriver driver = new FirefoxDriver();

driver.get("https://letskodeit.teachable.com/p/practice");

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

driver.manage().window().maximize();

}

@Test

public void checkRadioOptions() {

/*List<WebElement> element = driver.findElements(By.xpath("//input[@type='radio']"));*/
List<WebElement> element = driver.findElements(By.name("cars"));


boolean flag = false;

flag = element.get(1).isSelected();

if (flag==true) {

    System.out.println("Do Nothing");
}
    else {

        element.get(2).click();
        }
}

}

java.lang.NullPointerException at automate.FunctionalTest.checkRadioOptions(FunctionalTest.java:38) 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) at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:100) at org.testng.internal.Invoker.invokeMethod(Invoker.java:646) at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:811) at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1129) at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:129) at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:112) at org.testng.TestRunner.privateRun(TestRunner.java:746) at org.testng.TestRunner.run(TestRunner.java:600) at org.testng.SuiteRunner.runTest(SuiteRunner.java:366) at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:361) at org.testng.SuiteRunner.privateRun(SuiteRunner.java:319) at org.testng.SuiteRunner.run(SuiteRunner.java:268) at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52) at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86) at org.testng.TestNG.runSuitesSequentially(TestNG.java:1264) at org.testng.TestNG.runSuitesLocally(TestNG.java:1189) at org.testng.TestNG.runSuites(TestNG.java:1104) at org.testng.TestNG.run(TestNG.java:1076) at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:126) at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:152) at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:57)

  • Post your code please. – FDM Oct 5 '16 at 10:05
  • Just check I have added the script code as well. – User6 Oct 5 '16 at 10:20
  • At which line exactly is the code crashing? Can't see rule numbers here. – FDM Oct 5 '16 at 10:56
  • Got the cause.Thanks FDM. next time will post along with rule numbers – User6 Oct 6 '16 at 3:53
2

WebDriver driver = new FirefoxDriver();

The driver was already created in the starting. This line was causing the error as it was assigning the driver to a new variable.

It should have been driver = new Firefox Driver();

Not the answer you're looking for? Browse other questions tagged or ask your own question.