Espresso Webview select hidden element

2019-08-14 06:08发布

问题:

How do you find a hidden element inside an Android Webview using espresso? This is what I tried:

onWebView().withElement(findElement(Locator.CSS_SELECTOR, "#clsp:hidden"));

That produces the following stacktrace.

java.lang.RuntimeException: java.lang.RuntimeException: Error in evaluationEvaluation: status: 13 value: {message=An invalid or illegal selector was specified} hasMessage: true message: An invalid or illegal selector was specified at android.support.test.espresso.web.sugar.Web$WebInteraction$ExceptionPropagator.(Web.java:323) at android.support.test.espresso.web.sugar.Web$WebInteraction.doEval(Web.java:292) at android.support.test.espresso.web.sugar.Web$WebInteraction.withElement(Web.java:208) at com.middlestump.MainActivityInstrumentationTest.createAlert(MainActivityInstrumentationTest.java:89) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)

The MainActivityInstrumentationTest.java:89 bit is the line of code I have given.

Also tried:

onWebView().withElement(findElement(Locator.CSS_SELECTOR, "#clsp")).check(isDisplayed());

But there is a type mismatch between WebAssertion and ViewAssertion

回答1:

Swipe webview and find the hidden element:

onView(withId(R.id.webView)).perform(ViewActions.swipeUp());