Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

464
Views
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("https://www.amazon.com.tr/") at Actor.WebTest (.\steps_file.js:20:12) 

Thanks in advance

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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

about 4 years ago · Juan Pablo Isaza Report

0

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}`);
    }
  });
}
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!