所选节点没有表单祖先-Mink错误 [英] The selected node does not have a form ancestor - Mink error

查看:100
本文介绍了所选节点没有表单祖先-Mink错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Mink和Goutte驱动程序在Magento安装上执行测试,而当我尝试在按钮上使用click()press()函数时,该操作将失败.

I'm trying to perform tests on my Magento installation using Mink with Goutte driver, and it fails when I'm trying to use click() or press() functions on a button.

代码:

$page = $this->getSession()->getPage();
    $checkout = $page->find('css', '.btn-proceed-checkout');
    $checkout->click();

如何进行这项工作?为什么Mink实际上需要表单来单击按钮元素?还是与Goutte无法获取JS有关的问题?

How to get this work? Why does Mink actually need a form to click a button element? Or is that the problem connected with Goutte not being able to fetch JS?

推荐答案

TL; DR:使用其他驱动程序或确保表单元素实际上位于表单内部.

TL;DR: use different driver or make sure form elements are actually inside the form.

Goutte驱动程序非常棒,但不如真正的浏览器那么棒.它获取响应内容并使用Goutte抓取器对其进行分析.为了增加一些测试的趣味性,它允许您通过拦截值设置调用并将表单数据存储在对象中来输入和提交表单数据.当您单击一个按钮(我假设仅在type="submit"上)时,表单数据将添加到请求数据中并发送到服务器.

Goutte driver is pretty awesome, but not as awesome as the real browser. It gets the response content and uses Goutte scrapper to analyse it. To add some spice your testing it allows you to enter and submit form data by intercepting value setting calls and storing form data in the object. When you click on a button (I'd assume only on type="submit") that form data is added into request data and sent to the server.

为了创建该表单对象,它会搜索最接近的父表单以获取基本的表单详细信息.因此,当您尝试在不属于表单的输入中设置一个值,或者在没有表单的情况下进行提交时–找不到表单并引发异常.

In order to create that form object it searches for the closest parent form to get the basic form details. So, when you try to set a value on the input that is not part of the form, or do a submit without a form – it can't find the form and throws an exception.

确保将表单元素放在form标记内应该可以解决此类问题.另外,您也可以使用Selenium2驱动程序–它使用完全不同的机制.

Ensuring that form elements sit inside the form tag should resolve such issues. Alternatively you can use Selenium2 driver – it uses a completely different mechanism.

这篇关于所选节点没有表单祖先-Mink错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆