4

我想使用 TestCafe 单击表单中的提交按钮。这是按钮的样子:

<button type="submit" class="btn btn-lg btn-cart pull-left">
<span class="hidden-xs hidden-sm">
     <i class="fa fa-shopping-basket"></i>&nbsp;&nbsp;
</span>
     Add To Cart
</button>

此按钮位于表单内:

<form name="product1" action="domain.tld/product" method="post" role="form">
</form>

在我的测试中,我想将产品添加到购物车:

test('add it', async t =>{
     await t
          .click(Selector('button[type="submit"]'))
});

问题是,在 nabber 中是另一个类型为 submit 的按钮。如何使用此特定按钮将我的产品添加到购物车?

4

2 回答 2

4

您可以使用更具体的选择器通过此按钮执行操作。例如,如果此按钮具有另一个提交按钮没有的类,则使用它来制作更具选择性的选择器。

让我们考虑一个例子。另一个提交按钮没有pull-left类。使用以下选择器Selector('button[type="submit"].pull-left')Selector('.btn.pull-left').

如果这些按钮没有区别,可以使用 Selector 的方法nth(index): Selector('button[type="submit"]').nth(1)在我们的文档中查看更多信息。

于 2017-12-05T13:25:22.510 回答
2

Submit the second form :

$('form').eq(1).submit();

You don't need to find the submit button and trigger a click on that. Instead, you can just call .submit() on the form itself.

于 2017-12-05T12:56:56.427 回答