让我们说,我有一个表格:
<form action="test.php" method="post">
<input type="text" name="myinput" value="3" />
<button>Submit</button>
</form>
这是我对Crawler的过滤和测试:
$client = static::createClient();
$crawler = $client->request('GET', 'test.php');
$filter = 'button';
$buttonNode = $crawler->selectButton($crawler->filter($filter));
$this->assertEquals(1, $buttonNode->count()); // this works
$form = $buttonNode->form(); // This shows error "LogicException: Unable to submit on a "input" tag."
$client->submit($form);
答案 0 :(得分:2)
我认为问题出在按钮的定义中。我将重命名它只是为了更好地理解并在那里添加类型:
<button type="submit">SubmitLabel</button>
然后它应该像我这样工作:
$client = static::createClient();
$crawler = $client->request('GET', 'test.php');
$buttonCrawlerNode = $crawler->selectButton('SubmitLabel');
$form = $buttonCrawlerNode->form();
$client->submit($form);
答案 1 :(得分:0)