微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ReferenceError: $ 未定义 (Selenium::WebDriver::Error::JavascriptError)

如何解决ReferenceError: $ 未定义 (Selenium::WebDriver::Error::JavascriptError)

我正在尝试使用 selenium webdriver 为 http://automationpractice.com/index.php?controller=authentication&back=my-account 编写自动化脚本并使用 jest 运行测试

我将创建帐户按钮定义为,

 get createAccountBtn() {
    return $("#SubmitCreate");
  }

这里使用的是,

 createAcctBtnIsVisible() {
    this.createAccountBtn.waitForExist();
  } 

在我的测试中,我用它来断言按钮是可见的,如下所示:

test("it loads the create account button",async () => {
    expect(authPageForms.createAcctBtnIsVisible).tobedefined();
  });

通过了。

我也有一个使用这个选择器的函数,然后点击创建帐户按钮并像这样定义它,

 submitNewEmail() {
    this.createAccountBtn.waitForExist();
    this.createAccountBtn.click();
  }

在我的测试中,这是它正在执行的断言

test("it does not allow the user to continue without entering a valid email address",async () => {
    authPageForms.submitNewEmail();
    expect(errorMsg).toBe("Invalid email address.");
  });

但是,当我运行它时,我收到一个错误,指出 $ 未定义

ReferenceError: $ is not defined
 
       9 | 
      10 |   get createAccountBtn() {
    > 11 |     return $("#SubmitCreate");
         |     ^
      12 |   }

我不确定为什么会发生这种情况。感谢您的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。