Get the Value of HTML Element Using JSDom

  Kiến thức lập trình

Seems like this should be really fundamental action, yet I can’t find any documentation or examples on how to do this. If I have some HTML, and I want to retrieve a particular value and set it as a variable, how do I do that?

Example:

<html>

<head>
  <title>Working...</title>
</head>

<body>
  <form method="POST" name="hiddenform" action="https://someUrl/"><input type="hidden" name="id_token" value="xxxxxxxxxx.

My attempt to extract value:

const { JSDOM } = require('jsdom');

const kmsiResponse = await post(
      {
        ctx: loginCtx,
        hpgRequestId: loginSessionId,
        flowToken: loginSft,
        canary: loginCanary,
      },
      { url: 'myUrl' }
    );

    const kmsiResponseText = await kmsiResponse.text();
    const kmsiDom = new JSDOM(kmsiResponseText);
    console.log('JSDOM', kmsiDom.window.document.getElemenByName('id_token'));

Output:
JSDOM NodeList {}

2

LEAVE A COMMENT