How to filter by id with Symfony 2 Dom Crawler?

Sukhrob picture Sukhrob · Oct 29, 2012 · Viewed 12.3k times · Source

This works

$this->assertEquals(1, $crawler->filter('.elementClass')->count()); // filter by class

But, this doesn't seem to work.

$this->assertEquals(1, $crawler->filter('#elementId')->count()); // filter by id

Any ideas?

Answer

Igor picture Igor · Oct 29, 2012

Symfony2 DOM Crawler filter internally uses DOMXPath, so you can find answer for your question on this thread

query for filter should be something like(note that code bellow is untested, I'm sure link above will help you)

//*[@id='elementId']