-
Notifications
You must be signed in to change notification settings - Fork 369
06 WebView Support
Calabash supports querying and acting on webview content.
To look into a webview you simply use the query function and syntax. The syntax for webviews is a bit irregular (and we will clean this up at some point), but there is quite good support.
Here are some examples:
-
Query for an element with id, class or tagname
query("webView css:'#header'") query("webView css:'.js-current-repository'") query("webView css:'a'")
The string after css: can be any css selector.
-
Get all the HTML associated with the webview:
query("webView css:'*'")
Note query will only return DOM nodes that are visible on the screeen! (They should be visible and their center should be within the webview viewport).
As usual, anything you can query, you can touch (but the element must be visible to be found).
query("webView css:'a'").first
touch("webView css:'a'")
We recommend touching an input field to show the keyboard, and using keyboard_enter_char
and keyboard_enter_text
.
It is also possible to enter text through JavaScript, but realize that this may behave slightly differently than what happens when using the keyboard (e.g. event listeners may not be triggered). You can use the set_text
function to set the text using JavaScript (your query must be a textfield or textarea).
set_text "webView css:'input.login'", "ruk"
You can also evaluate JavaScript in a web view:
js = 'document.body.innerHTML'
query("webView", :stringByEvaluatingJavaScriptFromString => js)