用Behat填充隐藏的输入 [英] Filling in hidden inputs with Behat

查看:64
本文介绍了用Behat填充隐藏的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写Behat测试,我需要更改隐藏输入字段的值

I am writing Behat tests and I need to change the value of a hidden input field

<input type="hidden" id="input_id" ..... />

我需要更改此输入字段的值,但我一直在获取

I need to change the value of this input field, but I keep getting

Form field with id|name|label|value "input_id" not found

我一直在使用该步骤

$steps->And('I fill in "1" for "input_id"', $world);

是否需要做一些特殊的事情来修改隐藏的输入字段?

Is there something special which needs to be done to modify hidden input fields?

推荐答案

尽管用户无法填充隐藏字段,但在某些情况下希望能够填充隐藏字段以进行测试(通常是规则)有例外).您可以在要素上下文类中使用下一步,以按名称填充隐藏字段:

Despite the fact that user can't fill hidden fields, there are some situations when this is desirable to be able to fill hidden field for testing (as usually rules have exceptions). You can use next step in your feature context class to fill hidden field by name:

/**
 * @Given /^I fill hidden field "([^"]*)" with "([^"]*)"$/
 */
public function iFillHiddenFieldWith($field, $value)
{
    $this->getSession()->getPage()->find('css',
        'input[name="'.$field.'"]')->setValue($value);
}

这篇关于用Behat填充隐藏的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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