Cannot find xpath , may be some webview context problem

Hi,

I am trying to test web application through appium. I opened a page in chrome but after that it doesnt recognise xpath.
I searched the web , may be the problem is due to some context web view. But in my case, it shows only native conext not web conetxt.

Code

WebDriver driver;

@Before
public void setup() throws MalformedURLException
{
	DesiredCapabilities capabilities = DesiredCapabilities.android();
	capabilities.setCapability("BROWSER_NAME","chrome");
	capabilities.setCapability("deviceName","Redmi 3s");
	capabilities.setCapability("PLATFORM","Android");
	capabilities.setCapability("VERSION","6.0.0");
	
	capabilities.setCapability("appPackage", "com.android.chrome");
	capabilities.setCapability("appActivity", "com.google.android.apps.chrome.Main");
	//capabilities.setCapability("autoWebview", "true"); - tried using this also, but no luck
	driver = new AndroidDriver( new URL("http://127.0.0.1:4723/wd/hub"),capabilities);
	driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
	//WebView.setWebContentsDebuggingEnabled(true); - no luck using this 
	
}

@Test
public void test_login()
{
	driver.get("http://automationpractice.com/index.php");   
	//driver.manage().timeouts().implicitlyWait(25, TimeUnit.SECONDS);
	//driver.findElement((By.xpath("//*[@id='header']/div[2]/div/div/nav/div[1]/a"))).click();

	Set<String> contextNames = ((AppiumDriver) driver).getContextHandles();
	for (String contextName : contextNames) {
	System.out.println(contextName);   --- prints out only  NATIVE_APP
	}
	((AppiumDriver) driver).context("WEBVIEW_1");
	//driver.findElement((By.xpath("//login[@text='Sign in']"))).click();
	Set<String> contextNames1 = ((AppiumDriver) driver).getContextHandles();
	for (String contextName : contextNames1) {
	System.out.println(contextName); //prints out something like NATIVE_APP \n WEBVIEW_1
	}
} 

Appium log

[AndroidDriver] Found webviews: []
[AndroidDriver] Available contexts: [“NATIVE_APP”]
[AndroidDriver] Shutting down Android driver

Please let me know how this can be resolved.
I am using appium v 1.6.4 and all latest jars , also my android phone is android 6.

Hi,
Someone please help me. I am stuck here.

try your luck with

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

Hi,
No luck :frowning:
ADB] Running ‘C:\Users\dedua\android-sdks\platform-tools\adb.exe’ with args: ["-P",5037,"-s",“e241d2fb7ce4”,“shell”,“am”,“force-stop”,“io.appium.unlock”]
[AndroidDriver] Not cleaning generated files. Add clearSystemFiles capability if wanted.
[MJSONWP] Encountered internal error running command: Error: unknown error: Failed to clear data for com.android.chrome on device e241d2fb7ce4: Error: java.lang.SecurityException: PID 20701 does not have permission android.permission.CLEAR_APP_USER_DATA to clear data of package com.android.chrome

(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64)
at Chromedriver.callee$2$0$ (C:\Users\dedua\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\appium-chromedriver\lib\chromedriver.js:176:15)
at tryCatch (C:\Users\dedua\AppData\Local\Programs\appium-desktop\resources\app\node_modules\appium\node_modules\babel-runtime\regenerator\runtime.js:67:40)

Error

org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{PLATFORM=Android, appPackage=com.android.chrome, appActivity=com.google.android.apps.chrome.Main, BROWSER_NAME=chrome, VERSION=6.0.0, browserName=chrome, platformName=Android, version=, deviceName=Redmi 3s, platform=ANY}], required capabilities = Capabilities [{}]
Build info: version: ‘unknown’, revision: ‘5234b32’, time: ‘2017-03-10 09:00:17 -0800’
System info: host: ‘DEDUA-WS02’, ip: ‘10.65.54.170’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_131’
Driver info: driver.version: AndroidDriver
at io.appium.java_client.remote.AppiumProtocolHandShake.lambda$1(AppiumProtocolHandShake.java:96)
at java.util.Optional.orElseThrow(Unknown Source)
at io.appium.java_client.remote.AppiumProtocolHandShake.createSession(AppiumProtocolHandShake.java:96)
at io.appium.java_client.remote.AppiumCommandExecutor.doExecute(AppiumCommandExecutor.java:111)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:162)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
at io.appium.java_client.DefaultGenericMobileDriver.(DefaultGenericMobileDriver.java:38)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:88)
at io.appium.java_client.AppiumDriver.(AppiumDriver.java:112)
at io.appium.java_client.android.AndroidDriver.(AndroidDriver.java:73)
at one.Web_Test.setUp(Web_Test.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)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:24)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

java.lang.NullPointerException
at one.Web_Test.tearDown(Web_Test.java:61)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:33)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

Hopefully !! this video helps you https://youtu.be/sGuEgo2HIXw