ReferenceError: $ is not defined (Selenium::WebDriver::Error::JavascriptError)

I am playing around writing an automation script for http://automationpractice.com/index.php?controller=authentication&back=my-account using selenium webdriver and running the tests with jest

I have the create account button defined as,

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

and it is used here,

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

In my test I used this to assert that the button is visible, like so:

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

It passes.

I also have a function using this selector to then click on the create accountbutton and have it defined like this,

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

In my test this is the assertion it is performing

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

However, when I run it, I get an error that $ is not defined

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

I am not sure why this is happening. Thank you for helping.

Source: Ask Javascript Questions

LEAVE A COMMENT