Behat/Mink找不到ID的字段 [英] Behat/Mink doesn't find field by id
本文介绍了Behat/Mink找不到ID的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试填写一个字段. 为什么Behat找不到ID的字段?
I am trying to fill out a field. Why does Behat not find the field by id?
输入字段:
<input class="js-text-full text-full form-text required" data-drupal-selector="edit-field-article-nr-supplier-0-value" type="text" id="edit-field-article-nr-supplier-0-value" name="field_article_nr_supplier[0][value]" value="" size="60" maxlength="255" placeholder="" required="required" aria-required="true">
PHP代码:
public function fillField($field, $value)
{
$field = $this->fixStepArgument($field);
$value = $this->fixStepArgument($value);
$this->getSession()->getPage()->fillField($field, $value);
}
注意:
When I fill in "edit-field-article-nr-supplier-0-value" with "12"
它说找不到ID的字段:
It says it doesn't find a field by id:
When I fill in "edit-field-article-nr-supplier-0-value" with "12" # Drupal\DrupalExtension\Context\MinkContext::fillField()
Form field with id|name|label|value|placeholder "edit-field-article-nr-supplier-0-value" not found. (Behat\Mink\Exception\ElementNotFoundException)
推荐答案
我找到了解决方法.我用javascript填写了输入内容
I found a work around. I filled out the input filed with javascript
/**
* @When I fill in :value on the field :field with javascript
*/
public function findAllInputFields($value, $field){
$javascript = "window.onload = function () {var e = document.getElementById('$field').value='$value';}";
$this->getSession()->executeScript($javascript);
}
重要,不要忘记@javascript注释.
Important, don't forget the @javascript annotation.
@javascript
Scenario: Fill out field
When I fill in 12 on the field "edit-field-article-nr-supplier-0-value" with javascript
如果有人有更好的解决方案,请与我分享.
If someone has a better solution, please share I would like to know.
这篇关于Behat/Mink找不到ID的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文