I am getting NullPointerException everytime I try to run below code at code line element.click()
Note : It passes if I comment the last line of code. Also similar question was asked here but it didn't help.
AndroidDriver driver;
@Test
public void TestAppium() throws Exception{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "MotoG5s Plus");
capabilities.setCapability("platformVersion", "7.1.1");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("noReset", "true");
File file = new File("D:\\Appium Workspace\\AppiumDemo\\apk\\MakeMyTrip Flights Hotels Cabs IRCTC Rail Bookings_v7.3.2_apkpure.com.apk");
capabilities.setCapability("app", file.getAbsolutePath());
driver = new AndroidDriver(new URL("http://10.80.196.55:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Thread.sleep(10000);
WebElement element = driver.findElementById("com.makemytrip:id/my_profile_icon");
element.click();
}
Also my driver onject is not null as you can see from below screenshot
Also the element is not null as you can see in screenshot below :-
I have even put the thread.sleep() in case it is because of loading. The ID given in findelementbyid() method is correct. And also it launches the app and then it
It Launches the app and then it throws below error message :-
java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at Appiumcapabilities.TestAppium(Appiumcapabilities.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:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:580)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:716)
I am using selenium-java-3.9.1 and appium server 1.7.1, testNG Windows 10, appium-java-client version 4.1.0