4

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 ?

Thomas
  • 43
  • 5

1 Answers1

4

Try something like

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

and see if it works.

Jack Fleeting
  • 24,385
  • 6
  • 23
  • 45
  • That worked, had to add a $myInput->click(); afterwards. So the filterXPath seems to open the pulldown and select the value and just needs a click. My solution opened the pulldown, but was never able to select any values. Thank you ! – Thomas Nov 05 '20 at 15:20
  • Done. Was actually trying to do that yesterday, but could not find how to do it :| Had to google to find out :) Could have been better GUI there.... – Thomas Nov 06 '20 at 14:04