Search code examples
css-selectorsgatling

How do I extract meta tag content using CSS selectors in Gatling check?


My page has a meta tag containing the csrf token:

<meta name="_csrf" content="somestring">

I'd like to use css-selectors to grab the content:

action.check(css("meta[name=\"_csrf\"]", "content").saveAs("x-csrf-token"))

However, this fails with the error:

css((meta,Some(content))).find(0).exists, found nothing

What is the correct way to extract the content of the meta tag?


Solution

  • In this particular case, the issue was malformed html:

    <html>
        <head>
            <head>
            </head>
            <meta name="_csrf" content="abc123">
        </head>
    </html>
    

    Browsers ignored the bad markup, but Gatling/whatever library it uses under the hood did not.

    I have not yet investigated whether this is a bug or should/could be easily changed.