JZK
JZK

Reputation: 577

Symfony crawler select tag attributes from dropdown

I need to target "selected" attribute in drop down menu so I can compare if item marked as selected is the item what I need to have selected. Can you help me with methods, what I can use for this ?

<option value="Title" selected>Title</option>
<option value="First Name">First Name</option>
<option value="Middle Name">Middle Name</option>

Thank you :)

Upvotes: 2

Views: 1475

Answers (2)

JZK
JZK

Reputation: 577

I've found an answer finally -

$crawler->filter('option[selected]')->attr('value');

works for me :)

Upvotes: 5

scoolnico
scoolnico

Reputation: 3135

Maybe something like that (not tested)

$target = $crawler->filterXPath('//.../option/@selected')->text();

or

$target = $crawler->filterXPath('//.../option')->attr('selected')->text();

Upvotes: 0

Related Questions