【问题标题】:test something: selector needs to be typeof `string` or `function`测试一些东西:选择器需要是 typeof `string` 或 `function`
【发布时间】:2022-01-05 20:31:19
【问题描述】:

我想在 Visual Studio Code/Codeceptjs 上编写测试。简而言之,我的代码在这里:

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
   }  
  });
}

但是错误信息。为什么选择器需要是 typeof 'string' 或 'function.我可以为这个问题做些什么:

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)

您可以在场景步骤中看到 click() 为空。

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) 

提前致谢

【问题讨论】:

  • 表示选择器未定义,请调试代码
  • 感谢您的回答。我很有帮助。

标签: javascript webdriver-io codeceptjs


【解决方案1】:

定位器出错。尝试不带@ 符号的定位器名称input [id = "sp-cc-accept"]。 或者就像这样this.click('#sp-cc-accept')。 并阅读更多doc

【讨论】:

  • 感谢您的回答。我用另一种方式解决了我的问题。
猜你喜欢
  • 1970-01-01
  • 2023-03-08
  • 1970-01-01
  • 2017-01-31
  • 2017-09-10
  • 2020-02-03
  • 2019-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多