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" ...

+3
javascript selenium selenium-webdriver webdriver appium


source to share


No one has answered this question yet

See similar questions:

2
how to execute custom javascript code in webdriverjs
1
Unable to execute java script using Android Driver

or similar:

887
Convert character to ASCII code in JavaScript
860
How do I execute a JavaScript function when I have its name as a string
651
How do I get JavaScript to work after the page has loaded?
90
JavaScript execution using Selenium WebDriver in C #
2
Appium server 1.2.0.1 shows error when running script
1
Unusual Appium ENOENT Exception
0
Failed to run any test on Appium 1.4.13.1 for Android on windows
0
The returned value cannot be converted to WebElement: {element-6066-11e4-a52e-4f735466cecf = 1, ELEMENT = 1} in Android
0
Msgstr "Unable to start WebDriver session." the error occurs when opening the app with appium and protractor
0
Running selenium webscript script in android browser using appium, browser initiated on emulator but chrome edge exception thrown



All Articles
Loading...
X
Show
Funny
Dev
Pics