Forum Xamarin Xamarin Test Cloud (Read Only)

WebView control with a colon in the id

How can I e.g. enter text into a html input field when the id has a colon within? I.e. when I create a tree of the current view the id is set on the control but it appears like this:

[dom] id: "userForm:username"
[dom] id: "userForm:userFirstName"

Trying to enter text with app.EnterText(c => c.Css("#userForm:username"), "Monkey") results in an error:

{"reason":"sh.calaba.instrumentationbackend.query.ast.InvalidUIQueryException: Exception while running query: #userForm:username. SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '#userForm:username' is not a valid selector.","outcome":"ERROR","detail":"java.lang.RuntimeException: sh.calaba.instrumentationbackend.query.ast.InvalidUIQueryException: Exception while running query: #userForm:username. SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '#userForm:username' is not a valid selector.\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith.evaluateWithViews(UIQueryASTWith.java:67)\n\tat sh.calaba.instrumentationbackend.query.ast.evaluation.UIQueryEvaluationStep.step(UIQueryEvaluationStep.java:40)\n\tat sh.calaba.instrumentationbackend.query.ast.evaluation.QueryEvaluator.evaluateQueryForPath(QueryEvaluator.java:19)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryEvaluator.evaluateQueryForPath(UIQueryEvaluator.java:52)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryEvaluator.evaluateQueryWithOptions(UIQueryEvaluator.java:16)\n\tat sh.calaba.instrumentationbackend.query.Query.executeQuery(Query.java:68)\n\tat sh.calaba.instrumentationbackend.actions.HttpServer.serve(HttpServer.java:308)\n\tat sh.calaba.instrumentationbackend.actions.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:478)\n\tat java.lang.Thread.run(Thread.java:841)\nCaused by: sh.calaba.instrumentationbackend.query.ast.InvalidUIQueryException: Exception while running query: #userForm:username. SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '#userForm:username' is not a valid selector.\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith$1.call(UIQueryASTWith.java:214)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith$1.call(UIQueryASTWith.java:197)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith.evaluateWithViews(UIQueryASTWith.java:64)\n\t... 8 more\n"}
   at Xamarin.UITest.Android.AndroidGestures.Query[T](ITokenContainer query, Object[] args, String methodName)
   at Xamarin.UITest.Android.AndroidGestures.<QueryGestureWait>c__AnonStorey1.<>m__0()
   at Xamarin.UITest.Shared.WaitForHelper.WaitForAnyOrDefault[T](Func`1 query, T[] defaultValue, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout)
Error while performing EnterText(Css("#userForm:username"), "Monkey")
Exception: System.Exception: Unable to find element. Query for Css("#userForm:username") gave no results.
   at Xamarin.UITest.SharedApp.FirstWithLog[T](T[] results, ITokenContainer tokenContainer)
   at Xamarin.UITest.Android.AndroidApp.<EnterText>c__AnonStorey7.<>m__0()
   at Xamarin.UITest.Utils.ErrorReporting.With(Action func, Object[] args, String memberName)
Exception: Error while performing EnterText(Css("#userForm:username"), "Monkey")

Is there any way I could access this control via the ID? I tried escaping the semicolon which lead to no output at all...

Best Answer

  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai
    Accepted Answer

    @MarkAllibone I know this is getting a bit ridiculous, but I believe eight backslashes will work
    8 -> 4 in C#. 4 backslashes are now passed to the Calabash server. The Calabash server reads this as 2 backslashes in the query parser. Now these two backslashes are supplied to JavaScript, becoming one slash

Answers

  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai

    This stackoverflow post says that you can use a backslash to escape a colon: http://stackoverflow.com/a/122266/4547279

  • mallibonemallibone USUniversity ✭✭

    Hey @TobiasRoikjer thanks for your suggestion, yeah I already tried that. It then does not throw any error but also does not execute the commant. It simply gets skipped...

  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai

    @MarkAllibone That sounds strange, does querying for the view yield no results?

  • mallibonemallibone USUniversity ✭✭

    @TobiasRoikjer yeah strange indeed. When I query for "#userForm:usernameField" I get nothing, when I query for a field that does not exist I get a response.

    Here is a copy and paste from the REPL:

    app.Query(c => c.Css("#userForm:usernameField"))
    app.Query(c => c.Css("#usernameField"))

    Query for Css("usernameField") gave 0 results.
    [
    
    ]
    
  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai
    edited July 2016

    I guess since this is C# you have to escape the backslash, e.g.

     app.Query(c => c.Css("#userForm\\:usernameField"))
    
  • mallibonemallibone USUniversity ✭✭
    edited July 2016

    @TobiasRoikjer I was really hoping I was making such a silly mistake but unfortunately no luck... :disappointed: here is the output when I adopt the query as you suggested:

    app.Query(c => c.Css("#desktopLogin\:usernameField"))

    Error while performing Query(Css("#desktopLogin\:usernameField"))
    Exception: System.Exception: Query for Css("#desktopLogin\:usernameField") failed with outcome: ERROR
    Status: 200
    Contents:
    {"reason":" no viable alt; token=null (decision=15 state 1) decision=<<>>","outcome":"ERROR","detail":"java.lang.RuntimeException:  no viable alt; token=null (decision=15 state 1) decision=<<>>\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.getErrorMessage(UIQueryLexer.java:42)\n\tat org.antlr.runtime.BaseRecognizer.displayRecognitionError(BaseRecognizer.java:195)\n\tat org.antlr.runtime.Lexer.reportError(Lexer.java:261)\n\tat org.antlr.runtime.Lexer.nextToken(Lexer.java:99)\n\tat org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:133)\n\tat org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:127)\n\tat org.antlr.runtime.CommonTokenStream.consume(CommonTokenStream.java:67)\n\tat org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:108)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryParser.filter(UIQueryParser.java:594)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryParser.expr(UIQueryParser.java:266)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryParser.query(UIQueryParser.java:124)\n\tat sh.calaba.instrumentationbackend.query.Query.parseQuery(Query.java:123)\n\tat sh.calaba.instrumentationbackend.query.Query.executeQuery(Query.java:59)\n\tat sh.calaba.instrumentationbackend.actions.HttpServer.serve(HttpServer.java:308)\n\tat sh.calaba.instrumentationbackend.actions.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:478)\n\tat java.lang.Thread.run(Thread.java:841)\nCaused by: NoViableAltException('\\'@[])\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.mESC_SEQ(UIQueryLexer.java:1134)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.mSTRING(UIQueryLexer.java:924)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.mTokens(UIQueryLexer.java:1578)\n\tat org.antlr.runtime.Lexer.nextToken(Lexer.java:89)\n\t... 12 more\n"}
       at Xamarin.UITest.Android.AndroidGestures.Query[T](ITokenContainer query, Object[] args, String methodName)
       at Xamarin.UITest.Android.AndroidApp.<Query>c__AnonStorey1.<>m__0()
       at Xamarin.UITest.Utils.ErrorReporting.With[T](Func`1 func, Object[] args, String memberName)
    Exception: Error while performing Query(Css("#desktopLogin\:usernameField"))
    
  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai

    Could you try with four slashes?

  • mallibonemallibone USUniversity ✭✭

    Ah I see because the string will get passed onto the Java Runtime... unfortunately still no luck... I tried it further with 3 backslashes which also resulted in an error...

    app.Query(c => c.Css("#desktopLogin\\:usernameField"))

    Error while performing Query(Css("#desktopLogin\\:usernameField"))
    Exception: System.Exception: Query for Css("#desktopLogin\\:usernameField") failed with outcome: ERROR
    Status: 200
    Contents:
    {"reason":"sh.calaba.instrumentationbackend.query.ast.InvalidUIQueryException: Exception while running query: #desktopLogin:usernameField. SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '#desktopLogin:usernameField' is not a valid selector.","outcome":"ERROR","detail":"java.lang.RuntimeException: sh.calaba.instrumentationbackend.query.ast.InvalidUIQueryException: Exception while running query: #desktopLogin:usernameField. SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '#desktopLogin:usernameField' is not a valid selector.\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith.evaluateWithViews(UIQueryASTWith.java:67)\n\tat sh.calaba.instrumentationbackend.query.ast.evaluation.UIQueryEvaluationStep.step(UIQueryEvaluationStep.java:40)\n\tat sh.calaba.instrumentationbackend.query.ast.evaluation.QueryEvaluator.evaluateQueryForPath(QueryEvaluator.java:19)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryEvaluator.evaluateQueryForPath(UIQueryEvaluator.java:52)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryEvaluator.evaluateQueryWithOptions(UIQueryEvaluator.java:16)\n\tat sh.calaba.instrumentationbackend.query.Query.executeQuery(Query.java:68)\n\tat sh.calaba.instrumentationbackend.actions.HttpServer.serve(HttpServer.java:308)\n\tat sh.calaba.instrumentationbackend.actions.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:478)\n\tat java.lang.Thread.run(Thread.java:841)\nCaused by: sh.calaba.instrumentationbackend.query.ast.InvalidUIQueryException: Exception while running query: #desktopLogin:usernameField. SyntaxError: Failed to execute 'querySelectorAll' on 'Document': '#desktopLogin:usernameField' is not a valid selector.\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith$1.call(UIQueryASTWith.java:214)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith$1.call(UIQueryASTWith.java:197)\n\tat sh.calaba.instrumentationbackend.query.ast.UIQueryASTWith.evaluateWithViews(UIQueryASTWith.java:64)\n\t... 8 more\n"}
       at Xamarin.UITest.Android.AndroidGestures.Query[T](ITokenContainer query, Object[] args, String methodName)
       at Xamarin.UITest.Android.AndroidApp.<Query>c__AnonStorey1.<>m__0()
       at Xamarin.UITest.Utils.ErrorReporting.With[T](Func`1 func, Object[] args, String memberName)
    Exception: Error while performing Query(Css("#desktopLogin\\:usernameField"))
    
  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai

    What was the error for six backslashes?

  • mallibonemallibone USUniversity ✭✭

    Here you go:

    app.EnterText(c => c.Css("#desktopLogin\\\:usernameField"), "Foo")

    Exceptions while waiting for any:
    System.Exception: Query for Css("#desktopLogin\\\:usernameField") failed with outcome: ERROR
    Status: 200
    Contents:
    {"reason":" no viable alt; token=null (decision=15 state 1) decision=<<>>","outcome":"ERROR","detail":"java.lang.RuntimeException:  no viable alt; token=null (decision=15 state 1) decision=<<>>\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.getErrorMessage(UIQueryLexer.java:42)\n\tat org.antlr.runtime.BaseRecognizer.displayRecognitionError(BaseRecognizer.java:195)\n\tat org.antlr.runtime.Lexer.reportError(Lexer.java:261)\n\tat org.antlr.runtime.Lexer.nextToken(Lexer.java:99)\n\tat org.antlr.runtime.BufferedTokenStream.fetch(BufferedTokenStream.java:133)\n\tat org.antlr.runtime.BufferedTokenStream.sync(BufferedTokenStream.java:127)\n\tat org.antlr.runtime.CommonTokenStream.consume(CommonTokenStream.java:67)\n\tat org.antlr.runtime.BaseRecognizer.match(BaseRecognizer.java:108)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryParser.filter(UIQueryParser.java:594)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryParser.expr(UIQueryParser.java:266)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryParser.query(UIQueryParser.java:124)\n\tat sh.calaba.instrumentationbackend.query.Query.parseQuery(Query.java:123)\n\tat sh.calaba.instrumentationbackend.query.Query.executeQuery(Query.java:59)\n\tat sh.calaba.instrumentationbackend.actions.HttpServer.serve(HttpServer.java:308)\n\tat sh.calaba.instrumentationbackend.actions.NanoHTTPD$HTTPSession.run(NanoHTTPD.java:478)\n\tat java.lang.Thread.run(Thread.java:841)\nCaused by: NoViableAltException('\\'@[])\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.mESC_SEQ(UIQueryLexer.java:1134)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.mSTRING(UIQueryLexer.java:924)\n\tat sh.calaba.instrumentationbackend.query.antlr.UIQueryLexer.mTokens(UIQueryLexer.java:1578)\n\tat org.antlr.runtime.Lexer.nextToken(Lexer.java:89)\n\t... 12 more\n"}
       at Xamarin.UITest.Android.AndroidGestures.Query[T](ITokenContainer query, Object[] args, String methodName)
       at Xamarin.UITest.Android.AndroidGestures.<QueryGestureWait>c__AnonStorey1.<>m__0()
       at Xamarin.UITest.Shared.WaitForHelper.WaitForAnyOrDefault[T](Func`1 query, T[] defaultValue, Nullable`1 timeout, Nullable`1 retryFrequency, Nullable`1 postTimeout)
    Error while performing EnterText(Css("#desktopLogin\\\:usernameField"), "Foo")
    Exception: System.Exception: Unable to find element. Query for Css("#desktopLogin\\\:usernameField") gave no results.
       at Xamarin.UITest.SharedApp.FirstWithLog[T](T[] results, ITokenContainer tokenContainer)
       at Xamarin.UITest.Android.AndroidApp.<EnterText>c__AnonStorey7.<>m__0()
       at Xamarin.UITest.Utils.ErrorReporting.With(Action func, Object[] args, String memberName)
    Exception: Error while performing EnterText(Css("#desktopLogin\\\:usernameField"), "Foo")
    
  • TobiasRoikjerTobiasRoikjer DKXamarin Team Xamurai
    Accepted Answer

    @MarkAllibone I know this is getting a bit ridiculous, but I believe eight backslashes will work
    8 -> 4 in C#. 4 backslashes are now passed to the Calabash server. The Calabash server reads this as 2 backslashes in the query parser. Now these two backslashes are supplied to JavaScript, becoming one slash

  • mallibonemallibone USUniversity ✭✭

    @TobiasRoikjer thanks that was it! - if we ever meet in person, remind me to get you a beer :smile:

Sign In or Register to comment.