Symfony2 InvalidArgumentException:当前节点列表为空
Symfony2 InvalidArgumentException: The current node list is empty
我正在进行功能测试,但遇到错误
InvalidArgumentException: The current node list is empty
这是我的代码
public function testThis(){
$requestContent = [
'val1' => '324343',
'valname' => '"Benjamin"',
'valLast' => '"A"',
'valnum' => '44343',
'hndval1' => '0000',
'hdnval2' => '0000',
'hndval3' => '1111',
'hndref' => '"ThisIsAtest"',
'hdnMessage' => '"I am a message"'
];
$crawler = $this->client->request('GET', '/');
$submitButton = $crawler->selectButton('btnSubmit');
$form = $submitButton->form($requestContent);
print_r($form);
$this->client->followRedirects(true);
$crawler = $this->client->submit($form);
$response = $this->client->getResponse();
$request = $this->client->getRequest();
print_r($crawler->html());
$this->assertRegExp('/\/nextPage', $request->getUri());
print_r($request->getUri());
$a = $crawler->filter('input[name="pageName"]');
$this->assertContains(
"True",
$a->attr('value')
);
}
我认为这是错误的:
$form = $submitButton->form($requestContent);
请注意,$requestContent 值来自一个隐藏的输入类型,它们都在表单标签内。
您必须向 $crawler->selectButton()
提供按钮的文本。
// For a given HTML button:
// <input type="button" value="Upload File" />
// or
// <button type="button">Upload File</button>
$crawler->selectButton("Upload File");
旁注,您的正则表达式模式 '/\/nextPage'
无效。您需要添加一个结尾 /
--> '/\/nextPage/' // This will match the exact string: "/nextPage"
你还没有发布你的 HTML 所以现在我假设你的 HTML 例如:
<html>
<form method='GET' action='your action here'>
/*
* all other html here
*/
<input type='submit' value='Submit' id='btnSubmit' name='btnSubmit'>
</form>
</html>
$submitButton = $crawler->selectButton('btnSubmit');
改变
$submitButton = $crawler->selectButton('Submit');
因为 selectButton() 接受按钮值而不是 id 或 name。
确保这对您有所帮助。
我正在进行功能测试,但遇到错误
InvalidArgumentException: The current node list is empty
这是我的代码
public function testThis(){
$requestContent = [
'val1' => '324343',
'valname' => '"Benjamin"',
'valLast' => '"A"',
'valnum' => '44343',
'hndval1' => '0000',
'hdnval2' => '0000',
'hndval3' => '1111',
'hndref' => '"ThisIsAtest"',
'hdnMessage' => '"I am a message"'
];
$crawler = $this->client->request('GET', '/');
$submitButton = $crawler->selectButton('btnSubmit');
$form = $submitButton->form($requestContent);
print_r($form);
$this->client->followRedirects(true);
$crawler = $this->client->submit($form);
$response = $this->client->getResponse();
$request = $this->client->getRequest();
print_r($crawler->html());
$this->assertRegExp('/\/nextPage', $request->getUri());
print_r($request->getUri());
$a = $crawler->filter('input[name="pageName"]');
$this->assertContains(
"True",
$a->attr('value')
);
}
我认为这是错误的:
$form = $submitButton->form($requestContent);
请注意,$requestContent 值来自一个隐藏的输入类型,它们都在表单标签内。
您必须向 $crawler->selectButton()
提供按钮的文本。
// For a given HTML button:
// <input type="button" value="Upload File" />
// or
// <button type="button">Upload File</button>
$crawler->selectButton("Upload File");
旁注,您的正则表达式模式 '/\/nextPage'
无效。您需要添加一个结尾 /
--> '/\/nextPage/' // This will match the exact string: "/nextPage"
你还没有发布你的 HTML 所以现在我假设你的 HTML 例如:
<html>
<form method='GET' action='your action here'>
/*
* all other html here
*/
<input type='submit' value='Submit' id='btnSubmit' name='btnSubmit'>
</form>
</html>
$submitButton = $crawler->selectButton('btnSubmit');
改变
$submitButton = $crawler->selectButton('Submit');
因为 selectButton() 接受按钮值而不是 id 或 name。
确保这对您有所帮助。