How to wait for an element to be visible/clickable in appium with javascript?

I have written tests where is simply do:

        return driver.elementById(this.countryCodeSpinner).click()

but this scenario is failing randomly.
I want to do something like
return driver.wait(until(elemment is visible,10sec)).click()

can anyone please guide me to get the correct syntax in javascript as I can see answers implemented in Java but not in javascript.

hi there, sorry this is not going to help you…but can I ask how did you instantiate the appiumdriver in Javascript?

I am having so many issues, like you everything seems to be in Java!

Many thanks for any help

wd.js is the node.js webdriver which you need to use for appium with javascript:

var wd = require("wd"),
var driver = wd.promiseChainRemote(serverConfig);
return driver.init(desired_capabilites)

Let me know if you need further explanation of the process.

do you mind me asking what your desired_caps and serverConfig is? Are you executing on a real device or sim? Also have you started appium as a separate process? mine looks like this:

appium - ./node_modules/.bin/appium

caps: browserName: ‘’,
platformName: ‘iOS’,
platformVersion: ‘10.2’,
deviceName: ‘iPhone 6’,
app: ‘’

I am using appium 1.6.3

Many thanks for your help!

I have configured the following configurarion in both android and ios(in ios adding a different desired caps).
Under my project directory, I have created following js files in a folder named Setup

  1. appium_servers.js (you can also define your cloud credentials here if you are running the tests on cloud)

     exports.local = {
     host: 'localhost',
     port: 4723 };
  2. desired_caps.js (in the same file you can define the desired caps of ios)

    exports.desiredCapsAndroid = {
    appiumVersion: '1.6.3',
    deviceName: 'yourdevicename',
    platformVersion: '6.0.1',
    platformName: 'Android',
    name: 'Sample Test',
    app: 'path of your ipa or apk',
  3. logging.js (used for logging the requests and response with different colours to make the log more readable)

     "use strict";
     exports.configure = function (driver) {
     // See whats going on
     driver.on('status', function (info) {
     driver.on('command', function (meth, path, data) {
     console.log(' > ' + meth.yellow, path.grey, data || '');
     driver.on('http', function (meth, path, data) {
     console.log(' > ' + meth.magenta, path, (data || '').grey);
  4. setup.js (it contains all the required packages/libraries, just do npm install name to install any of them)

     var wd = require("wd");
     var mocha = require("mocha");
     var should = require("should");

5.After that in my test file I have written:

"use strict";
var testData = require("../Helper/test_data.js");
var wd = require("wd"),
_ = require('underscore'),
serverConfigs = require('../Setup/appium_servers.js');

describe("Test Case 1", function () {
    var driver;
    var allPassed = true;
    before(function () {
        var serverConfig = serverConfigs.local;
        driver = wd.promiseChainRemote(serverConfig);
        var desired = _.clone(require("../Setup/desired_caps.js").desiredCapsAndroid);
        return driver
    after(function () {
        return driver
    afterEach(function () {
        allPassed = allPassed && this.currentTest.state === 'passed';
        //For screenshot
        if (this.currentTest.state !== 'passed'){
            return driver.takeScreenshot().then(function(){
                return driver.saveScreenshot('../Screenshots/')

I am using real device but configuration will remain same for emulators also except for the device name/uuid in desired caps.
I have installed appium globally by doing npm install -g appium and starting it as a separate process and then run test cases by going into the test directory and doing mocha test_file.js
Hope this helps.

For anyone still stuck at using implicit wait in javascript with appium use:

return driver.waitForElementById(id, asserters.isDisplayed, 10000, 100)

Hi, would you please tell me in place of id have to use id but in place of asserters.isDisplayed what to use? I got stuck here