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
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);
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.
UPDATE:
Scenario:
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"
My FeatureContext:
/**
* @When I fill the form with :arg1
*/
public function iFillForm($json) {
$formHelper = FormHelper::getInstance($this->getSession());
$formHelper->fill($json);
}
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);
}
}
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.
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);
instead of
$page->fillField($key, $value);