You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #60781 [DomCrawler] Allow selecting buttons by their value (MatTheCat)
This PR was merged into the 6.4 branch.
Discussion
----------
[DomCrawler] Allow selecting `button`s by their `value`
| Q | A
| ------------- | ---
| Branch? | 6.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Issues | Fix#58509
| License | MIT
`Crawler::selectButton` can select an `input` by its `value`, which is tested but not documented.
However, it cannot select a `button` by its `value`. I don’t think this is intentional, which is why I opened this PR as a bugfix.
I also updated `Crawler::selectButton`’s PHPDoc and tests to better reflect what it does.
Commits
-------
c45ecfa [DomCrawler] Allow selecting `button`s by their `value`
Copy file name to clipboardExpand all lines: src/Symfony/Component/DomCrawler/Crawler.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -770,12 +770,12 @@ public function selectImage(string $value): static
770
770
}
771
771
772
772
/**
773
-
* Selects a button by name or alt value for images.
773
+
* Selects a button by its text content, id, value, name or alt attribute.
774
774
*/
775
775
publicfunctionselectButton(string$value): static
776
776
{
777
777
return$this->filterRelativeXPath(
778
-
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))
778
+
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 contains(concat(\'\', normalize-space(string(@value)), \'\'), %2$s) or @id=%3$s or @name=%3$s]', 'translate(@type, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", "abcdefghijklmnopqrstuvwxyz")', static::xpathLiteral(''.$value.''), static::xpathLiteral($value))
0 commit comments