我如何使用赛普拉斯从隐藏输入中获取值?

How would I get the value from the hidden input using Cypress?

我需要保存存储在这个隐藏输入中的令牌。

这是我的要求:

cy.request({
  method: 'GET',
  url: '/auth/login',
  body: {
    email: email,
    password: password,
  },
}).then((response) => {
    const page = response.body;
});

response.body returns:

<!DOCTYPE html>
<html>
    <body>
        <form class="form" action="" method="post" autocomplete="off">
            <input id="email" class="form-control" type="text" name="email" placeholder="Email" />
            <input id="password" class="form-control" type="password" name="password" placeholder="Password" />
            <input type="hidden" name="_token" value="c5LWQtrMVkKXxBFKs1zFzrJYq4PgNifndvcV0F6O">
            <button type="submit">Login</button>
            <a href="https://testing.com">Other Login</a>
        </form>
    </body>
</html>

我不确定如何 find/grab 来自名称为 _token

的隐藏输入的值

来自柏树CSRF example:

  it('strategy #1: parse token from HTML', function () {

    // to fetch the login page, and then parse the HTML contents
    // to find the CSRF token embedded in the page
    cy.request('/auth/login')
    .its('body')
    .then((body) => {
      // we can use Cypress.$ to parse the string body
      // thus enabling us to query into it easily
      const $html = Cypress.$(body)
      const token = $html.find('input[name=_token]').val()

      ...[see link for full code]
    })