Support for WebKit.WKWebView

Does Xamarin UI Test framework support WKWebView? I can't manage to get it work, cause it could not find WebView to perform XPath selection.

Best Answer

Answers

  • EvgenyPopovEvgenyPopov USMember

    Thanks a lot Glenn! I will give it a try.

  • Hi,

    I'm trying to work with WKWebView in Xamarin.UITest.

    Css and Xpath work, e.g.
    app.Query(c=>c.Class("WKWebView").Css("*"));
    app.Query(c=>c.Class("WKWebView").XPath("//a"));

    However, when trying to use InvokeJS on the WKWebView, like this:
    app.Query(c=>c.Class("WKWebView").InvokeJS("alert('hello');"));

    ...I get this error:
    Error while performing Query(Class("WKWebView").InvokeJS("alert('hello');")) Exception: System.Exception: Javascript invoked on non-webview
    at Xamarin.UITest.iOS.iOSGestures.InvokeJS (Xamarin.UITest.Queries.IInvokeJSAppQuery invokeJsAppQuery) [0x00057] in :0
    at Xamarin.UITest.iOS.iOSApp+c__AnonStorey3.<>m__0 () [0x00012] in :0
    at Xamarin.UITest.Utils.ErrorReporting.With[T] (System.Func`1[TResult] func, System.Object[] args, System.String memberName) [0x00010] in :0

    Is there any way to invoke a JavaScript statement on a WKWebView from Xamarin.UITest?
    It seems to be possible from a Calabash query:
    https://github.com/calabash/calabash-ios/wiki/06-WebView-Support

    Any help is appreciated.

    Regards,
    Matthias

  • EmrahDautbegovicEmrahDautbegovic USMember ✭✭

    Hi,
    I have also problems with WKWebView, I cannot access to any of DOM elements inside.
    I am using the following command:

    app.Query( x => x.Class("WKWebview")) and I'm getting result.

    but when I try something like this:

    app.Query( x => x.Class("WKWebview").Css(".someclass"))

    I get the following exception:

    Exception: Newtonsoft.Json.JsonReaderException: Error reading string. Unexpected token: StartObject. Path 'Class', line 10, position 13.
    at Newtonsoft.Json.JsonReader.ReadAsStringInternal () [0x000ac] in :0
    at Newtonsoft.Json.JsonTextReader.ReadAsString () [0x00000] in :0
    at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.ReadForType (Newtonsoft.Json.JsonReader reader, Newtonsoft.Json.Serialization.JsonContract contract, System.Boolean hasConverter) [0x0006d] in :0

  • EvanTsai.0791EvanTsai.0791 USMember
    edited September 1

    I tried to use <br class='abc'> tag

    I am able to get the class content by using
    app.Query(c => c.Class("WKWebView").Css("*")).First().Class;

    However, if I use <h1> tag, it does not work.

  • Karthikeyan1993Karthikeyan1993 USMember ✭✭

    @MatthiasFueller.8286 @EmrahDautbegovic Have you found any solution for this?

  • EmrahDautbegovicEmrahDautbegovic USMember ✭✭

    Hi @KarthikeyanVengidusamy.0809 ,
    I found some. Every query should be like app.Query(x => x.Class("WKWebVIew").Css("something"))
    You should carefully write Css. I had a problem with svg inside my WebView because it is impossible to access the element inside svg. The other DOM elements are accessible.

  • Karthikeyan1993Karthikeyan1993 USMember ✭✭

    Thanks! @EmrahDautbegovic Do you have any idea about InvokeJS in WKWebView?

  • EmrahDautbegovicEmrahDautbegovic USMember ✭✭

    @KarthikeyanVengidusamy.0809 Not really, I've tried it but without any success. I used also Xpath few months ago when I faced this problem and made some progress, so I advice you to use Xpath. Also, if you make something with InvokeJS please let me know :)

Sign In or Register to comment.