PROBLEM CLICKING WITH A ROBOT USING PUPPETEER

Asked

Viewed 420 times

-2

I am creating this robot to automate some tasks of the I day by day, I ask him to access the site, click the input, and then log in. He accesses the page, but he’s not clicking, I can’t find the problem. this is the code

const puppeteer = require('puppeteer');

(async () =>{
    const browser = await puppeteer.launch({ headless: false });
    const site = 'http://www.goolsystem.com.br';
    const page = await browser.newPage();
    await page.goto('http://www.goolsystem.com.br/4/Login.aspx?ReturnUrl=%2f4');
    await page.waitFor('#ucTrocarModulo_btnIconeUrbano > input');
    await page.click('#ucTrocarModulo_btnIconeUrbano > input');
    await page.type('input[name="ucLogarUsuario$txtLogin"]','@@@@@', {delay: 100});
    await page.type('input[name="ucLogarUsuario$txtSenha"]', '@@@@@', {delay: 100});
    await page.keyboard.press('Enter');

    await browser.close();
})();

when I run shows the following error: "(Node:5920) Unhandledpromiserejectionwarning: Unhandled Promise rejection. This error either originated by Throwing Inside of an async Function without a catch block, or by rejecting a Promise which was not handled with . (catch). To terminate the Node process on unhandled Promise rejection, use the CLI flag --unhandled-rejections=strict (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (Ode:5920) [DEP0018] Deprecationwarning: Unhandled Promise rejections are deprecated. In the Future, Promise rejections that are not handled will terminate the Node.js process with a non-zero Exit code."

1 answer

0


The input selector that wants to click this wrong, the id of the parent selector is ucTrocarModulo_moduloUrbano and you are using the id of the child selector which is ucTrocarModulo_btnIconeUrbano (the input) and trying to fetch an input within it, that is, you are trying to click an input inside the input you want to click, as it does not exist it presents the error.

Correct options:

1 - #ucTrocarModulo_moduloUrbano > input

2 - #ucTrocarModulo_moduloUrbano #ucTrocarModulo_btnIconeUrbano

3 - #ucTrocarModulo_btnIconeUrbano

You can use the element ID directly (as in option 3). Try this:

const puppeteer = require('puppeteer');

(async () =>{
    const browser = await puppeteer.launch({ headless: false });
    const site = 'http://www.goolsystem.com.br';
    const page = await browser.newPage();
    await page.goto('http://www.goolsystem.com.br/4/Login.aspx?ReturnUrl=%2f4');
    await page.waitFor('#ucTrocarModulo_btnIconeUrbano'); // ID do input
    await page.click('#ucTrocarModulo_btnIconeUrbano'); // ID do input
    await page.waitFor('#ucLogarUsuario_txtLogin'); 
    await page.type('#ucLogarUsuario_txtLogin','@@@@@', {delay: 100}); // ID do input Login
    await page.type('#ucLogarUsuario_txtSenha', '@@@@@', {delay: 100}); // ID do senha
    await page.keyboard.press('Enter');

    await browser.close();
})();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.