Unable to read the value from an input field in webview (hybrid app)

135 views
Skip to first unread message

Bojan Antic

unread,
Jan 19, 2017, 6:47:57 AM1/19/17
to calabash-android

Hello everyone,

Im trying to simply read a value from an input field, in the app. Essentially, im writing a test where i enter certain value into the input field, and i want to read what i have inputted, to make sure it is correct.  App is hybrid, and the input filed is in the webview. Its is simple PhoneNumber input field, but what ever type of input it is, i dont get the value. Here is the screen shot of queried input:

irb(main):009:0> query("webview css:'input'")
[
    [0] {
                "class" => "",
             "nodeType" => "ELEMENT_NODE",
                   "id" => "",
        "calSavedIndex" => 0,
                 "html" => "<input name=\"foo\" type=\"tel\" autocomplete=\"off\">",
          "textContent" => "",
                 "rect" => {
                   "y" => 564,
                   "x" => 108,
            "center_x" => 540,
              "height" => 150,
               "width" => 864,
                 "top" => 104,
                "left" => 36,
            "center_y" => 639
        },
             "nodeName" => "INPUT",
              "webView" => nil
    }
]


I have tried all kinds of things..

As you can see, there is no attribute  that shows value, even if there IS that attribute in that field. I can get the value through chrome://inspect/#devices just by reading value from a DOM element.

I have tried all kinds of things, 
Like query("webview css:'input'", :textContent) - witch is useless since we can see that it is an empty string.
So i tried something like this query("webview css:'input'", :value), also variations like :getValue. :values, :getText .etc.. Then i get next error:

  [0] {
                 "error" => "No key for textCOntent. Keys: [class, nodeType, id, calSavedIndex, textContent, html, rect, nodeName, webView]",
         "receiverClass" => "java.util.HashMap",
        "receiverString" => "{class=, nodeType=ELEMENT_NODE, id=, calSavedIndex=0, textContent=, html=<input name=\"foo\" type=\"tel\" autocomplete=\"off\">, rect={y=564, x=108, center_x=540, height=150, width=864, top=104, left=36, center_y=639}, nodeName=INPUT, webView=null}",
            "methodName" => "textCOntent"
    }

I have also tried stuff like this: 

irb(main):032:0> query("webview css:'input'", :method_name=>'getValue')
[
    [0] {
                 "error" => "No such method found: method_name([String])",
         "receiverClass" => "java.util.HashMap",
        "receiverString" => "{class=, nodeType=ELEMENT_NODE, id=, calSavedIndex=0, textContent=, html=<input name=\"foo\" type=\"tel\" autocomplete=\"off\">, rect={y=564, x=108, center_x=540, height=150, width=864, top=104, left=36, center_y=639}, nodeName=INPUT, webView=null}",
            "methodName" => "method_name"
    }
]


Even though these seem like Native commands, but still, tried them in webview, didnt work.
Does anyone have any idea of how to access value from an input field.

Thanks in advance. :) 
 

grze...@backbase.com

unread,
Jan 19, 2017, 7:12:10 AM1/19/17
to calabash-android
This is very interesting one. I run into exactly the same issue. 

Bojan Antic

unread,
Jan 19, 2017, 8:12:13 AM1/19/17
to calabash-android
I have also tried some JavaScript API that looks something like this: 
(note: example from the web)


> javascript =  "document.getElementsByTagName('h1').toString()"
> query("UIWebView", {calabashStringByEvaluatingJavaScript: javascript})
[
    [0] "[object NodeList]"
]

But it also doesn't work for me. Either because in my case, we use WebView, not UIWebView or this features is just not working properly, but still unable to get the value from an input field. 

Joshua Moody

unread,
Jan 19, 2017, 1:22:43 PM1/19/17
to calabash-android

Bojan Antic

unread,
Jan 20, 2017, 2:42:26 AM1/20/17
to calabash-android
Yes i did. Thing with those is that they mention WKWebView and UIWebView, and how query("WebView css:'.foo'") will target both WebView and UIWebView but i have tried it and it still doesn't work.
Reply all
Reply to author
Forward
0 new messages