phpsymfonyweb-crawlersymfony-panther

Symfony crawler select OPTION in SELECT list without FORM


I am crawling a website that has a SELECT that are freestanding with no FORM parent and no NAME, only ID.

<select id="ff-select-Choice" class="ff-form-control">
    <option value="">please select</option>
    <option value="val1">first</option>
    <option value="val2">second</option>
    <option value="val3">third</option>
</select>

I am able to select it with

$myInput = $crawler->filter('#ff-select-Choice');

and

$myInput->click();

will open the list, but how can I select a value in the list by value or name ?


Solution

  • Try something like

    $myInput = $crawler->filterXPath(".//select[@id='ff-select-Choice']//option[@value='val2']");
    

    and see if it works.