0

I am using the following code to create automation logic.

The code is as follows:

if (parameters.day) { const todayISOString = new Date().toISOString(); const today = ${todayISOString.split("-")[0]}${todayISOString.split("-")[1] }${todayISOString.split("-")[2].split("T")[0]};

  if (today !== parameters.day) {
    var date = parameters.day;
    console.log("has date: " + date);

    const year = date.substring(0, 4);
    const month = date.substring(4, 6);
    const day = date.substring(6, 8);
    const dateParsed = `${day}/${month}/${year}`;

    const weeksBox = await page.waitForSelector(selectors[parameters.fact + "ReportPage"].weeksBox);
    await weeksBox.click();
    console.log("OPEN DROPDOWN WEEK LIST...");

    //let datesList = await page.$$(selectors[parameters.fact + "ReportPage"].weekButton);
    let datesList = await weeksBox.$$("option");
    let dateElem = null;
    console.log(datesList.length);
    for (let i = 0; i < datesList.length; i++) {
      const e = datesList[i];

      let data = await e.evaluate((c) => c.innerText);
      if (dateParsed == data.trim()) {
        dateElem = e;
        debugger
        await e.click()
        break;
      }
    } /* 

The date that I passed in my parameters passes ok into my Variable dateParsed, but fail the click, can some one help me with my case?

Best regards, Nemesis

  • I don't think you can use `await e.click()`. From https://stackoverflow.com/questions/46342930/puppeteer-button-press, I would try `await e.evaluate(e => e.click());` – James Jan 21 '21 at 17:16
  • Hi James, despite not returning any error, it still does not select the date (dropdown list position) that I have set in my date parameters. However, although it receives the correct length from the dropdown list (53, the correct number that I get with the console.log(datesList.length);) it sets the e.evaluate to 0 and in this case, it should be 1, any suggestions for this new case? Once again many thanks for your help, I really appreciated it! – Nemesis Jan 21 '21 at 20:38
  • 1
    Hi there, I found a solution for this: let data = await e.evaluate((c) => c.innerText); if (dateParsed == data.trim()) { dateValue = await e.evaluate((c) => c.value); break; } } Many thanks for the help! Best regards, Nemesis – Nemesis Jan 25 '21 at 12:30

0 Answers0