Open
Description
Symfony version(s) affected
7.1
Description
The submitForm(string $button, ...)
method indicates :
@param string $button The text content, id, value or name of the form <button> or <input type="submit">
However, the value
attribute doesn't seem to be checked :
Symfony\Component\BrowserKit\Exception\InvalidArgumentException: There is no button with "btn_value" as its content, id, value or name.
How to reproduce
<form method="post">
<input type="text" id="name" name="name" required>
<button type="submit" id="btn_id" name="btn_name" value="btn_value">My button</button>
</form>
public function testFormButton(): void
{
$client = static::createClient();
$client->request('GET', '/');
$client->submitForm('My button', ['name' => 'John']);
$client->submitForm('btn_id', ['name' => 'John']);
$client->submitForm('btn_name', ['name' => 'John']);
$client->submitForm('btn_value', ['name' => 'John']); // this fails
}
Possible Solution
The XPath query behind this doesn't check the value
attribute of <button>
tags:
// Crawler.php
public function selectButton(string $value): static
{
return $this->filterRelativeXPath(
sprintf('descendant-or-self::input[((contains(%1$s, "submit") or contains(%1$s, "button")) and contains(concat(\' \', normalize-space(string(@value)), \' \'), %2$s)) or (contains(%1$s, "image") and contains(concat(\' \', normalize-space(string(@alt)), \' \'), %2$s)) or @id=%3$s or @name=%3$s] | descendant-or-self::button[contains(concat(\' \', normalize-space(string(.)), \' \'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(' '.$value.' '), static::xpathLiteral($value))
);
}
I can work on a PR if you confirm the issue. Thanks
Additional Context
No response