Unable to click/tap on a button in Android WebView

Hi everyone,

I got trouble when click or tap on “Try Again” button in the attached image.
This is a webview in Android native app. So I switched context to Webview, then able to detect the element and getText of it. But I cannot click on it.
I tried many solution such as: click by JavaScript/ Jquery, click by coordinates in webview (actions, touchActions of selenium) but unlucky.
Is there any way to resolve this?

Hi @baottran
Did you find any solution for this. I am facing the same problem. It would be of great help if you can help me with the solution.

Thanks,
Sravya

Hi @Sravya_Batchu,

Are you also switching to the WebView using Mobile.switchToWebView()? If so, how are you trying to tap the button in your test? Are you using Mobile.tap() or WebUI.click()? My guess would be that once in WebView, you’d need to use the WebUI functions.

– Chris

2 Likes

Hello @Chris_Trevarthen

My test case stops executing once I use Mobile.switchToWebView(), it throws no error, but the test case does not go to the next command. I have tried to switch to webview using appium command getContextHandles() and set the context to webview. It is still the same. I am able to see both the native and webview when I print out the contexts. I have no luck so far in making it work. I posted in katalon forum and commented on almost all the posts related to webview, but I haven’t got any response yet.

It would be of great help, if you can provide solution for this.

Thanks,
Sravya

I am using chromedriver 65 and running the tests on real android device.

Hi @Sravya_Batchu,

That’s a lot of good information, thank you! I’m curious what Katalon and Appium think are on the screen at the time you switch to the WebView. If you want to see some more detail about exactly what Appium/Katalon detects on the screen you can log out the XML contents of the screen. You should be able to do that by putting the following import statements at the top of your test case:

import com.kms.katalon.core.logging.KeywordLogger
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver

Then in the code for your test, add the following right after you switch to the WebView:

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
KeywordLogger log = new KeywordLogger()
log.logInfo(driver.getPageSource())

When the test runs, you should see an entry in the Log Viewer for “Statement - log.logInfo(driver.getPageSource())” that shows the start of the XML for the screen. If you tap on it, you’ll see all of the XML for the screen on the right-hand pane.

If you could attach that XML in a reply that would be helpful for troubleshooting.

Thanks,

Chris

Hi @Sravya_Batchu,
You should getPageSoure() following Chris’s steps first to know you are standing at correct webview context. In my case, I got coordinations of my element in Native app view and execute touch action.

TouchAction action = new TouchAction(driver);
action.tap(positionX, positionY).perform();
1 Like

Hi Chris,

I am using the code mentioned below to switch from Webview to Native view, but my execution is getting stopped at line AppiumDriver<?> driver = MobileDriverFactory.getDriver() and in the report I do not see any error.

AppiumDriver<?> driver = MobileDriverFactory.getDriver()
KeywordLogger log = new KeywordLogger()
log.logInfo(driver.getPageSource())
driver.context(“NATIVE_APP”)
def Object menuBtn = TestDataMethods.returnTestObject(Globals.ORPath_LogIn+“Android/”, “android.widget.ImageButton0”)
Mobile.tap(menuBtn)
Mobile.switchToWebView()

Report Error:
05-13-2019 11:44:07 AM - [FAILED] - Feature file ‘Include/features/WFN OTG/Settings/UserPreferences/Help/ValidationsofHelpUI.feature’ was failed
05-13-2019 11:44:07 AM - [FAILED] - Keyword runFeatureFile was failed (Root cause: Feature file ‘Include/features/WFN OTG/Settings/UserPreferences/Help/ValidationsofHelpUI.feature’ was failed)
05-13-2019 11:44:07 AM - [END] - End action : runFeatureFile
05-13-2019 11:44:07 AM - [FAILED] - Test Cases/WFN OTG/Functional/Settings/User Preferences/Help/TC004_ValidationsofHelpUI FAILED because (of) (Stack trace: com.kms.katalon.core.exception.StepFailedException: Keyword runFeatureFile was failed (Root cause: Feature file ‘Include/features/WFN OTG/Settings/UserPreferences/Help/ValidationsofHelpUI.feature’ was failed)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:36)
at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:56)
at com.kms.katalon.core.keyword.internal.KeywordMain$runKeyword.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:45)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile$0.callStatic(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallStatic(CallSiteArray.java:56)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:194)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callStatic(AbstractCallSite.java:214)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:95)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
at Script1555260565644.run(Script1555260565644.groovy:25)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:183)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:108)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:294)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:285)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:264)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:256)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:200)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:99)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:90)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:149)
at TempTestCase1557727869257.run(TempTestCase1557727869257.groovy:22)
at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:263)
at groovy.lang.GroovyShell.run(GroovyShell.java:518)
at groovy.lang.GroovyShell.run(GroovyShell.java:507)
at groovy.ui.GroovyMain.processOnce(GroovyMain.java:653)
at groovy.ui.GroovyMain.run(GroovyMain.java:384)
at groovy.ui.GroovyMain.process(GroovyMain.java:370)
at groovy.ui.GroovyMain.processArgs(GroovyMain.java:129)
at groovy.ui.GroovyMain.main(GroovyMain.java:109)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:109)
at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:131)

I am running my test on Android device. First I am lunching the application and then switching view to webview to Login into it. But I want to click on an object which is android object and cannot be clicked unless and until I Switch the view to Native. To do that I have tried using Mobile.SwitchNative() but the object is not getting recognized. So I have tried using Appium and still no luck.

Can you please help me in resolving this issue?

Thank you.

Regards,
Chandan

Hi @chandan.dungarwal2,

Can you please confirm that you have the imports at the top of your test file:

import com.kms.katalon.core.logging.KeywordLogger
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory
import io.appium.java_client.AppiumDriver

Is there any way you can share a screenshot or screen recording of what’s going in the login process?

Thanks,

Chris

How to setup Android web-view…?
I have Katalon studio, Appium, Android studio…
what can I do for Android web view for identify locators…?

Hi @Mohamed_Sajjaath,

You can try using MobileBuiltInKeywords.switchToWebView() in your test to switch the context to the web view, where you should have access to the elements:

Hope this helps,

Chris

i am facing this issue now my code structure is

Mobile.startApplication(‘C:\Users\\Downloads\6.apk’, false)

Mobile.tap(findTestObject(‘Page_Login/txt_config’), 1)

Mobile.setText(findTestObject(‘Page_Login/txt_config’), ‘testtesx’, 1)

Mobile.tap(findTestObject(‘Page_Login/btn_ok’), 1)

Mobile.switchToWebView()

2019-09-27 14:33:47.798 ERROR c.k.k.core.keyword.internal.KeywordMain  - ❌ Unable to switch the driver to WEBVIEW mode (Root cause: com.kms.katalon.core.exception.StepFailedException: Cannot find any WEBVIEW to switch to
	at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:50)
	at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.stepFailed(MobileKeywordMain.groovy:40)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword$_switchToWebView_closure1.doCall(SwitchToWebViewKeyword.groovy:74)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword$_switchToWebView_closure1.call(SwitchToWebViewKeyword.groovy)
	at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.runKeyword(MobileKeywordMain.groovy:21)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword.switchToWebView(SwitchToWebViewKeyword.groovy:67)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword.execute(SwitchToWebViewKeyword.groovy:62)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.switchToWebView(MobileBuiltInKeywords.groovy:854)
	at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords$switchToWebView$2.call(Unknown Source)
	at tc_mb_login.run(tc_mb_login:25)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1569574981133.run(TempTestCase1569574981133.groovy:21)
)
2019-09-27 14:33:47.802 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/tc_mb_login FAILED.
Reason:
com.kms.katalon.core.exception.StepFailedException: Cannot find any WEBVIEW to switch to
	at com.kms.katalon.core.keyword.internal.KeywordMain.stepFailed(KeywordMain.groovy:50)
	at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.stepFailed(MobileKeywordMain.groovy:40)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword$_switchToWebView_closure1.doCall(SwitchToWebViewKeyword.groovy:74)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword$_switchToWebView_closure1.call(SwitchToWebViewKeyword.groovy)
	at com.kms.katalon.core.mobile.keyword.internal.MobileKeywordMain.runKeyword(MobileKeywordMain.groovy:21)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword.switchToWebView(SwitchToWebViewKeyword.groovy:67)
	at com.kms.katalon.core.mobile.keyword.builtin.SwitchToWebViewKeyword.execute(SwitchToWebViewKeyword.groovy:62)
	at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)
	at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.switchToWebView(MobileBuiltInKeywords.groovy:854)
	at com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords$switchToWebView$2.call(Unknown Source)
	at tc_mb_login.run(tc_mb_login:25)
	at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
	at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
	at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1569574981133.run(TempTestCase1569574981133.groovy:21)

2019-09-27 14:33:47.806 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/tc_mb_login

Hi @Mohamed_Sajjaath,

Can you try inspecting the screen with Katalon’s Spy Mobile tool? I’m curious what it detects as elements on the screen at that time. Then can you provide a screenshot of what’s detected at that time as well as a screenshot of the app for that screen? Something like this:

Thanks,

Chris

After 2 days of try and error, you just solved my problems. Thanks @Chris_Trevarthen!! How does it not mention that anywhere =(

1 Like

@raissa can you please make it clearer how you solved the problem? since I’m facing the same issue

@Chris_Trevarthen
The same problem has not been solved.
It’s the same if you do what Docs tells you to do
Can you explain the solution in detail?