Behat/Mink/Selenium2元素不可见 [英] Behat/Mink/Selenium2 element is not visible

查看:66
本文介绍了Behat/Mink/Selenium2元素不可见的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用behat编写测试,当我尝试在引导程序模态内的输入上调用fillField时遇到一个问题. 当我在此输入中发送fillField时,硒引发异常:

I'm writing my tests with behat and I'm facing a problem when I try to call fillField on a input inside a bootstrap modal. When I send fillField in this input selenium throws an exception saying:

Element is not currently visible and so may not be interacted with

我已经手动创建了一个硒测试(通过selenium IDE),并在同一字段上调用了type,它运行良好.

I've created a selenium (via selenium IDE) test manually and called type on the same field and it worked fine.

$page = $this->getSession()->getPage()
$page->fillField("id_item", $value);

$value是我测试中的一个参数.我试图调用一个函数等待几秒钟,但效果不佳.

The $value is a parameter from my test. I've tried to call a function to wait some seconds, but it didn't worked as well.

更新:

场景:

Scenario: Realizar Pedido de Compra
Given I am on "/"
When I fill the form with "{\"id\": 1, \"items\":[{\"id_item\": 1}]}"
Then I should see "Ok"

我的FeatureContext:

My FeatureContext:

/**
 * @When I fill the form with :arg1
 */
public function iFillForm($json) {
    $formHelper = FormHelper::getInstance($this->getSession());
    $formHelper->fill($json);
}

在我的类FormHelper中:

In my class FormHelper:

public function fill($json) {
    $handler = new SelectorsHandler();
    $handler->registerSelector("css", new CssSelector());
    $fileJson = json_decode($json, true);
    $page = $this->session->getPage();
    foreach ($json as $key => $value) {
       if (is_array($value)) {
          $addSubGrid = $page->find("css", "#btn-plus-" . $key);
          if ($addSubGrid != null) {
             $subGrid = $page->find("css", "#" . $key);
             $formId = $subGrid->getAttribute("data-form");
             $ok = $page->find("css", "#$formId .btn-ok");
             foreach ($value as $formItem) {
                $itemFilled = array();
                $addSubGrid->click();
                $this->session->wait(
                   1000, "$('#modal-$formId').is(':visible')"
                );
                $this->fillForm($page, array("form-item" => $formItem), $itemFilled, false);
                $ok->press();
             }
          }
       } else {
          $page->fillField($key, $value);
       }
    }

$addSubGrid var是显示模态的要素.当我执行测试时,它会打开模态,但是当它进入$page->fillField($key, $value)时,它将不起作用.

The $addSubGrid var is the elment to show the modal. When I execute the test it opens the modal but when it goes into $page->fillField($key, $value) it does not work.

更新 我发现我正在尝试填写一个禁用字段.我启用了它,现在的问题是它不填充模式内部的字段,仅填充外部的字段.

UPDATE I've found that I was trying to fill a disabled field. I've enabled it and the problem now is that it does not fill the fields inside the modal, just the ones outside.

推荐答案

我设法使用驱动程序中的setValue来解决此问题.似乎貂皮的fillField有一个错误. 我用过:

I've managed to solve this using the setValue from the driver manually. It seems there's a bug with fillField from mink. I've used:

$this->session->getDriver()->setValue('//*[@id="'.$key.'"]', $value);

代替

$page->fillField($key, $value);

这篇关于Behat/Mink/Selenium2元素不可见的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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