解决方法
我不确定我到底需要什么,我想你有这样的形式
<form action="..." method="post"> ... <select id="my_form_category" name="my_form[category]"> <option value="1">category1</option> <option value="2">category2</option> <option value="3">category3</option> </select> ... <button type="submit">Edit</button> </form>
并且您想要选择category2.即使您不知道选项值,也可以使用爬虫来提取它
$client = static::createClient(); // go to form $crawler = $client->request('GET','...'); $value = $crawler->filter('#my_form_category option:contains("category2")')->attr('value'); $form = $crawler->selectButton('Edit')->form(); $form['my_form[category]']->select($value); // ... set other values $client->submit($form);