0

I'm wanting to bring the options of a select

But I've tried several ways and still nothing. I already got content from divs, labels and etc. But selecting is difficult The ID or queryselector is working because it brings an object of 35 elements (amount of options in the select itself)

But their content comes in white Now if I go to the console and use the same code to select it works

enter image description here

Here's the last code I tried, I've tried it in other ways too like queryselect, selectall

            await page.waitForSelector("#PlaceHolderMain_ddlPagamento", {
              timeout: 1500,
            });

            const select = await page.evaluate(() => {
              return document.getElementById("PlaceHolderMain_ddlPagamento");
            });

            console.log(select);

I took the screenshot to see if the select has information at the exact moment, I also confirmed that it has

Att

Ewerton Dutra
  • 17
  • 1
  • 7
  • 1
    You can't return nodes from `evaluate` like this. Return the text content from the node (`document.getElementById("PlaceHolderMain_ddlPagamento").textContent`), if that's what you're trying to get, otherwise use `evaluateHandle` or `page.$` to get an ElementHandle. See [Puppeteer page.evaluate is returning a undefined value](https://stackoverflow.com/questions/70973971/puppeteer-page-evaluate-is-returning-a-undefined-value). – ggorlen Aug 29 '22 at 16:14

1 Answers1

0
const optValue = await page.evaluate(async (pediCondicao) => {
  const options = document.querySelectorAll(
    "#PlaceHolderMain_ddlPagamento option"
  );

  for (let i = 0; i < options.length; ++i) {
    if (options[i].textContent!.trim() == pediCondicao) {
      return options[i].getAttribute("value");
    }
  }

  return null;
}, _PEDIDO.pedi_condicao);

if (!optValue) {

As I understand it, I only have access to the values inside evaluate

Even if I get the complete object or array with return

Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Ewerton Dutra
  • 17
  • 1
  • 7