Is it possible to select a link using its id or its class with the symfony crawler?
I tried:
$crawler()->selectLink('#return-button')->link();
$crawler()->selectLink('.btn.return')->link();
But I have the error:
InvalidArgumentException: The current node list is empty.
Does the selector only works using the content of the a
tag?
Try this:
This will return the link or button text, and then:
This is indeed better than selecting links by text. Best of luck :-)
Yes, it only works with the link text or
alt
attribute if your link is an image.The
filter()
method uses theCssSelector
component to transform a selector into an XPath expression and then callsfilterRelativeXPath()
just asselectLink()
does, so they return the same type and you should be able to just callIn case of a class selector that returns multiple matches, since
link()
only works on the first node, you'll need to calllinks()
instead:I dont think so:
where the $value is a string that is the link text:
symfony.component.domcrawler/Crawler/selectLink
But you can try:
or may, this is work with ids:
You should figure out to yourself, if check this:
symfony/components/dom_crawler