dtjmsy
dtjmsy

Reputation: 2762

fill in input empty but still have texts

I am using puppeteer to scrape a page, there is a simple form for searching on the page I enter a search text in one input, the others are empty, however, when i click on the search, the others input are not empty, what' s wrong with it ?

await page.goto('http://www.dollmedia-btp.com/annuaire/',  {waitUntil: 'domcontentloaded'});

await page.type("input#input-recherche-activite", "Maçonnerie");
await page.type("input#input-recherche-raison-sociale", "");
await page.type("input#input-recherche-ville","");
await page.type("input#input-recherche-tel", "");

I don' t know what to do, thanks for your helps

Upvotes: 0

Views: 481

Answers (1)

Yevhen Laichenkov
Yevhen Laichenkov

Reputation: 8692

You have to clear the fields, the type method with an empty string does not remove the input's value.

Custom function:

async function clear(page, selector) {
  await page.evaluate(selector => {
    document.querySelector(selector).value = "";
  }, selector);
}

Usage:

await clear(page,"input#input-recherche-raison-sociale");

Or without creating function:

await page.$eval('#input-recherche-raison-sociale', el => el.value = '');

Upvotes: 1

Related Questions