Appium & Webdriver (webdriverjs) - unable to execute javascript code
I am trying to execute javascript Appium test using WD . My code should look something like this:
"use strict";
var wd = require("wd");
var chai = require("chai");
var chaiAsPromised = require("chai-as-promised");
var jQuery = require("jQuery");
chai.use(chaiAsPromised);
chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
var desired = {
"appium-version": "1.0",
platformName: "iOS",
platformVersion: "7.1",
deviceName: "iPhone Retina (3.5-inch)",
app: "/Users/{myuser}/Library/Developer/Xcode/DerivedData/{MyApp}/Build/Products/Debug-iphonesimulator/MyApp.app",
};
var browser = wd.promiseChainRemote("0.0.0.0", 4723);
browser.init(desired).then(function() {
var getIframe = function(){
//var r = jQuery('#myIframe');
return {'response':"1"};//only for testing that this method works...
};
return browser
.elementByName("Show Webview").click()
.sleep(10000)
.contexts().then(function (contexts) { // get list of available views. Returns array: ["NATIVE_APP","WEBVIEW_1"]
return browser.context(contexts[1]); // choose the webview context
})
.execute(getIframe).then(function(res){
console.log(res);
})
.sleep(10000)
.fin(function() {
//return browser.quit();
});
}, function(e){console.log(e);}).done();
I am running this code with node mytest.js
.
The problem is that I cannot execute the js code. In this case, I get the following error:
Error: [execute()] Not JSON response
What am I doing wrong?
Comments:
-
What I am finally trying to do here is access and control the iFrame in my code (on the same domain) using
iFrame.contentDocument
-
My attachment to use 'execute like this: this post
Tpi, Yanov
UPDATE:
I was able to execute javascript using the safeExecute method instead of "execute". My problem is that I don't have access to the "window" object, so I cannot run "jQuery" or "window.document.getElementById" ...
source to share
No one has answered this question yet
See similar questions:
or similar: