E Dev
E Dev

Reputation: 51

Calabash how to select a value on a drop down select element in cordova app

I have this script in my .rb step definition file

touch("webView css:'select#MySelect'")

but I cannot query the option element and cannot find a way to access it with calabash, any help?

when I query the select element I get the following

[
    [0] {
             "center" => {
            "X" => 384,
            "Y" => 321
        },
            "webView" => "<UIWebView: 0x7fcdd2421e90; frame = (0 0; 768 1024); autoresize = W+H; layer = <CALayer: 0x7fcdd2456790>>",
           "nodeName" => "SELECT",
                 "id" => "ACTION_TYPE",
        "textContent" => "\n        \n      To DoPhone CallMeetingReminderOther",
              "class" => "",
               "rect" => {
                   "x" => 384,
              "height" => 40,
                   "y" => 321,
               "width" => 734,
                "left" => 17,
                 "top" => 301,
            "center_y" => 321,
            "center_x" => 384
        },
           "nodeType" => "ELEMENT_NODE"
    }
]

Upvotes: 0

Views: 852

Answers (3)

E Dev
E Dev

Reputation: 51

I found the solution

js = "document.getElementsByTagName('option')[3].selected = 'selected'" query("webView", {calabashStringByEvaluatingJavaScript: js})

Upvotes: -1

jmoody
jmoody

Reputation: 2480

On iOS, you should check out the xpath and JavaScript API.

https://github.com/calabash/calabash-ios/wiki/06-WebView-Support

There is also this sample app:

https://github.com/calabash/ios-webview-test-app

Upvotes: 0

Tobias
Tobias

Reputation: 678

The element being rendered probably doesn't have the type option. Use query("webview css:'*'") to find all elements and try locating the element in your console using a simple search for text.

Upvotes: 1

Related Questions