Home > Software engineering >  code gives an error after await is entered
code gives an error after await is entered

Time:03-27

I'm trying to make the program click onto a point on my screen needs the await to account for loading time but gives me VM9753:10 Uncaught ReferenceError: $ is not defined when ever it is run

code:

const sleep = ms => new Promise(r => setTimeout(r, ms));

// Click some buttons to start the quiz
$(".level_img").click();
$(".chipDesign.archivo-regular").click();
await sleep(5000);
$(".mat-button-wrapper").click();
await sleep(5000);
$(".mat-card.categories.catLength2.categories-0").click();

every thing works up until the await sleep if I get rid of the await sleep I get a Uncaught TypeError: Cannot read properties of null (reading 'click') error.

CodePudding user response:

You haven't provided much information but assuming you are using type script

Install npm node packages 

  // First install jQuery
   npm install --save jquery
  // and jQuery Definition
   npm install -D @types/jquery


Declare $ in your ts file 
import * as $ from 'jquery';

CodePudding user response:

Try to define the "$" as it says in your code

  • Related