問題描述
使用沒有保存按鈕的 Symfony 爬蟲發送表單(自動保存功能) (send form with Symfony crawler without save button (autosave function))
我正在為 symfony 編寫功能測試,但在頁面上發送表單時遇到問題,沒有任何保存按鈕,只有自動保存功能。
通常我首先找到保存按鈕,填寫帶數據的表格然後保存
// find the add button
$saveButton = $crawler‑>filter('button.btn‑save');
// fill the form with data and submit
$form = $saveButton‑>form();
// submit empty form
$crawler = $client‑>submit($form);
謝謝!
參考解法
方法 1:
You can call form() method on the form element itself.
$form = $crawler‑>filter('css‑selector‑to‑form')‑>form();
$crawler = $client‑>submit($form);