Unable to click/tap on a button in Android WebView


#1

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?


#2

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


#3

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


#4

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


#6

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


#7

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


#8

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();

#9

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


#10

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