Behat/Mink doesn't find field by id

…衆ロ難τιáo~ 提交于 2019-12-11 07:46:58

问题


I am trying to fill out a field. Why does Behat not find the field by id?

Input Field:

   <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 Code:

public function fillField($field, $value)
{
    $field = $this->fixStepArgument($field);
    $value = $this->fixStepArgument($value);
    $this->getSession()->getPage()->fillField($field, $value);
}

Behat:

When I fill in "edit-field-article-nr-supplier-0-value" with "12"

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)

回答1:


Mink's method fillField() uses findField() to find the field - and findField() uses name as selector and not id. That's why your initial approach didn't work. See source of Mink's class TraversableElement for details.




回答2:


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);
  }

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.



来源:https://stackoverflow.com/questions/54437349/behat-mink-doesnt-find-field-by-id

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!