mercredi 2 octobre 2019

Unable to detect if an element exists on a page or not in Puppeteer

I'm writing a bot for a pokemon MMORPG game. I wrote a script to login to my account and move around, the problem is that when I move around, I sometimes find a pokemon and then a new div is created which has the pokemon's data. I also get a button (with the id '#catch') to catch the pokemon. So I wrote the script such that it would check for the #catch button. Here's my code

while (true) {
    await page.waitFor(500);
    await page.keyboard.press("ArrowDown");
    if ((await page.$("input#catch")) != null) {
      console.log("Pokemon Found!");
    } else {
      console.log("No Pokemon Found");
    }

however, I get 'No Pokemon Found' every single time, even if there is one.

Aucun commentaire:

Enregistrer un commentaire