I'm trying to click a button using webdriver. Firepath is able to find the button using the xpath I'm giving but selenium is throwing null pointer exception. This page contains two buttons with same id and so, I tried traversing the hierarchy and found one button with a longer xpath.
Here is the HTML:
<section id="overview">
<button id="sign-me-up" class="next col-xs-10 col-xs-offset-1" ng- click="onclick($event, 'owner')">Sign Up Now</button>
My code looks like this: I tried several things here. Three different ways to see whether the element is visible or clickable.
driver.findElement(By.xpath(//section[@id='overview']/button)).click();
driver.findElement(By.xpath(//section[@id='overview']/button[@id='sign-me-up'])).click();
driver.findElement(By.xpath(signupButton)).isDisplayed();
For any of this above, selenium is throwing null pointer exception.
I'm missing something obvious here. Please help.
Full Stack Trace:
FAILED: OnboardAnIndividualProperty
java.lang.NullPointerException
at com.ys.page.SMBSignupLandingPage.assertIndividualOwnerPage(SMBSignupLandingPage.java:31)
at com.ys.tests.SMB.OnboardIndividualApplicationToApprovalState.OnboardAnIndividualProperty(OnboardIndividualApplicationToApprovalState.java:34)
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:84)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:714)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
at org.testng.TestRunner.privateRun(TestRunner.java:767)
at org.testng.TestRunner.run(TestRunner.java:617)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
at org.testng.SuiteRunner.run(SuiteRunner.java:240)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
at org.testng.TestNG.run(TestNG.java:1057)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:111)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:204)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:175)
Even this throws the NullPointerException:
driver.findElement(By.xpath(//section[@id='overview']
Does that mean I'm not passing the driver somewhere?
driver.findElement(By.xpath("//section/[@id='overview']"))
signupButton
.NullPointerException
? I'm curious because WebDriver is supposed to throwNoSuchElementException
when it cannot find a matching element. I guess you may getNullPointerException
becausedriver
variable is null.System.out.println("driver=" + driver);
just before exception is thrown, i.e., before line 31 ofSMBSignupLandingPage
class.