Test Something: Selector Needs to Be Typeof `String` or `Function`

I want to write test on Visual Studio Code/Codeceptjs. My code is here in short :

let amazonWebKeys=require('./amazonKeys/amazonwebkeys.json');

module.exports = function() {
  return actor({

    buttons:{
       acceptcookie :  '//input[@id="sp-cc-accept"]'   //accept cookie button  
                  
    },

    getParemeters : function(keys){
      return amazonWebKeys[keys];
    },

    WebTest:function(){
      this.amOnPage(this.getParemeters("url")); //go to website
      this.click(this.buttons.acceptcookie); //accept cookie
   }  
  });
}

But error message. Why selector needs to be typeof 'string' or 'function. What can I do for this problem :

1) WebTest
       test something:
     selector needs to be typeof `string` or `function`
      at Browser.findElements (node_modules\webdriverio\build\utils\index.js:176:11)        
      at Browser.$$ (node_modules\webdriverio\build\commands\browser\$$.js:6:44)
      at Browser.wrapCommandFn (node_modules\@wdio\utils\build\shim.js:63:38)

And you can see at Scenario Steps that in click() is empty.

Scenario Steps:
  - I.click() at Actor.WebTest (.\steps_file.js:21:12)
  - I.amOnPage("") at Actor.WebTest (.\steps_file.js:20:12) 

Thanks in advance

2

2 Answers

Error in the locator. Try the locator name input [id = "sp-cc-accept"] without the @ symbol. Or just like this this.click('#sp-cc-accept'). And read more doc

1

I also faced the same error. I solved it with the following code:

module.exports = function () {

  let parameters = require('./Parameters/parameters.json');

  username = '//input[@id="username"]';
  password = '//input[@id="password"]';
  submitButton = '//button[@class="btn btn-primary"]';
  administration = '//li[@id="admin-menu"]';

  return actor({

    getEnviromentParameters: function (key) {
      return parameters[key];
    },

    login: function () {
      this.amOnPage(this.getEnviromentParameters('loginUrl'));
      this.fillField(`${username}`, 
        this.getEnviromentParameters('userName')
      );
      this.fillField(`${password}`, 
        this.getEnviromentParameters('password')
      );
      this.click(`${submitButton}`);
      this.waitForElement(`${submitButton}`, 5)
      this.seeElement(`${submitButton}`);
    }
  });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Robert Thorne

Robert Thorne

Automotive & Future Transportation Editor

Robert Thorne covers electric vehicle innovations, autonomous driving systems, global mobility trends, and automotive engineering developments.

Share this article
Twitter Facebook Pinterest