Case 1: When using AndroidDriver object and calling WebDriver method “click”
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import io.appium.java_client.android.AndroidDriver;
public class TestApp
{
static RemoteWebDriver rDriver = null;
public static void main(String args[]) throws MalformedURLException
{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(“device”,“Android”);
capabilities.setCapability(“app”, “healthkart_prod.apk”);
capabilities.setCapability(“pltformName”, “ANDROID”);
capabilities.setCapability(“appPackage”, “com.healthkart.healthkart”);
capabilities.setCapability(“appActivity”, “com.healthkart.healthkart.Splash”);
capabilities.setCapability(“app”, “E:/healthkart_prod.apk”);
capabilities.setCapability(“deviceName”, “Android”);
capabilities.setCapability(“platformName”, “Android”);
AndroidDriver<WebElement> androidDriver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
androidDriver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
try
{
WebElement element = androidDriver.findElement(By.xpath("//android.widget.ImageButton[@content-desc='Navigate up']"));
element.click();
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Getting following exception:-
java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:279)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:83)
at com.healthkart.hkMsiteAutomation.regression.TestApp.main(TestApp.java:35)
Case 2:
AndroidDriver<WebElement> driver = new AndroidDriver<WebElement>(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
rDriver = driver;
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
try
{
WebElement element = rDriver.findElement(By.xpath("//android.widget.ImageButton[@content-desc='Navigate up']"));
element.click();
}
catch(Exception e)
{
e.printStackTrace();
}
}
Still getting same exception
CASE 3:
WebElement element = driver.findElement(By.xpath("//android.widget.ImageButton[@content-desc=‘Navigate up’]"));
driver.tap(1, element, 1);
Working fine for me. But the bottomline is that I am able to call methods of WebDriver but getting the above exception.