Capture screenshot in webview context

I am using Appium 1.2.3 and trying to capture the screenshot from the device using the following command:


It works fine in Native context, but fails when in webview context with the following message:

org.openqa.selenium.WebDriverException: unknown error: unhandled inspector error: {“code”:-32603,“message”:“Unable to capture screenshot”}
(Session info: webview=)
(Driver info: chromedriver=2.10.267521,platform=Windows NT 6.1 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 209 milliseconds
Build info: version: ‘2.42.2’, revision: ‘6a6995d31c7c56c340d6f45a76976d43506cd6cc’, time: ‘2014-06-03 10:52:47’
System info: host: ‘IT95MXR’, ip: ‘’, ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.8.0_20’
Driver info: io.appium.java_client.AppiumDriver
Capabilities [{app=C:\Users\Administrator\Desktop\Kotobi_3.2.0_Server_173_TESTING.apk, appPackage=com.vis.kotob, networkConnectionEnabled=true, warnings={}, databaseEnabled=false, deviceName=Android, platform=LINUX, appActivity=.ui.activity.splash.SplashActivity, desired={app=C:\Users\Administrator\Desktop\Kotobi_3.2.0_Server_173_TESTING.apk, appPackage=com.vis.kotob, appActivity=.ui.activity.splash.SplashActivity, newCommandTimeout=6000, browserName=, platformName=Android, deviceName=Android}, newCommandTimeout=6000, platformVersion=4.1, webStorageEnabled=false, locationContextEnabled=false, browserName=, takesScreenshot=true, javascriptEnabled=true, platformName=Android}]
Session ID: 25369dfe-eff7-4be2-98c3-57c650970420
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(
at java.lang.reflect.Constructor.newInstance(
at org.openqa.selenium.remote.ErrorHandler.createThrowable(
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(
at org.openqa.selenium.remote.RemoteWebDriver.execute(
at io.appium.java_client.AppiumDriver.execute(
at io.appium.java_client.AppiumDriver.execute(
at org.openqa.selenium.remote.RemoteWebDriver.getScreenshotAs(
at AppiumTest.loginTest(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(
at org.junit.runners.model.FrameworkMethod.invokeExplosively(
at org.junit.internal.runners.statements.InvokeMethod.evaluate(
at org.junit.internal.runners.statements.RunBefores.evaluate(
at org.junit.internal.runners.statements.RunAfters.evaluate(
at org.junit.runners.ParentRunner.runLeaf(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.BlockJUnit4ClassRunner.runChild(
at org.junit.runners.ParentRunner$
at org.junit.runners.ParentRunner$1.schedule(
at org.junit.runners.ParentRunner.runChildren(
at org.junit.runners.ParentRunner.access$000(
at org.junit.runners.ParentRunner$2.evaluate(
at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(
at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(
at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(
at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(
at org.apache.maven.surefire.booter.SurefireStarter.invokeProvider(
at org.apache.maven.surefire.booter.SurefireStarter.runSuitesInProcessWhenForked(
at org.apache.maven.surefire.booter.ForkedBooter.main(

I have also tried:

((TakesScreenshot) driver.context(“contextName”)).getScreenshotAs(OutputType.FILE)

and it fails with the same error. Does anyone have any idea why this is happening??

1 Like

Turned out to be an issue with ChrormeDriver :frowning:

1 Like

For anyone suffering from this issue, here is a possible workaround:

Switch to native context, take the screenshot and then switch back to the context you were in. Here is a code in Java that does that:

String contextName = driver.getContext();
File screenShot = driver.getScreenshotAs(OutputType.FILE);
driver.context(contextName );

Hope it helps somebody until they solve the bug :smile:


Below code is working fine for me:

public String Screenshotpath = "Mention the folder Location";
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(Screenshotpath+"Any name".jpg"));

The captured screenshot will be available in mentioned location.

1 Like

I’m also using such way - do perfect!

I tried such code and it didn’t work in my case :frowning:

Hey Hassan_Radi,

Even i am facing the same issue,Unable to capture the screenshot.Has the bug been fixed?At the moment i will try the workaround u suggested.

The ChromeDriver team has solved the bug, but I haven’t tried it myself yet. You can give it a try and let me know how it works for you, but so far I am using the workaround I mentioned before and it is working fine with me :smile:

Using the Workaround you suggested that works fine,Need to try the new chromedriver.

@Mayuresh_Shirodkar, @Hassan_Radi - Were you able to take the screenshot of the entire webpage or only the visible part of the screen on iOS or Android phone? Is there any way to take entire webpage screenshot? As using the above code I was only successful in capturing the visible content.
Any help would be appreciated.

It only takes a screenshot of the visible part of the webview. I didn’t come across such issue before as I only needed the visible part of the website. Anyway a possible workaroud would be to create your own function that scrolls and takes screenshots and then you can append those screenshots to create one big screenshot of the entire website.

Good luck!

1 Like

@Hassan_Radi - Thanks for replying. I’ll try that.

Thanks you Hassam Radi. This helps me