2012-10-30 28 views
0

比方說,我有一個表格:Symfony 2爬蟲窗體提交顯示錯誤「LogicException:無法在」輸入「標記上提交。」

<form action="test.php" method="post"> 
    <input type="text" name="myinput" value="3" /> 
    <button>Submit</button> 
</form> 

這是我的篩選,並與履帶測試:

$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

我不能讓Symfony2的TestClient的到提交沒有提交按鈕的表單。你可以使用像selenium,sahi或zombie.js這樣的測試,或者添加一個輸入提交按鈕,然後用css隱藏。 – Sgoettschkes

回答

0

你需要找到像我question的方式。

,或者它只是一個測試並沒有太多的測試,你可以使用casperJS

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);