getSession()->getPage(); // Assumes field collections will be in a sortable table. $table_xpath = 'table[contains(@class,"field-multiple-table")][contains(.,"' . $label. '")]'; $field_collection_region = $page->find('xpath', '//div[contains(@class,"field-type-field-collection")]'); $field_collection_table = $page->find('xpath', '//' . $table_xpath); $row = 1; foreach ($fcTable->getHash() as $fcRow) { $this_row = $field_collection_table->find('xpath', '//tbody/tr[' . $row . ']'); if (!$this_row) { throw new \Exception("Could not find table row $row"); } // Little hack to make sure wysiwyg will be filled. $this_row->findLink('Switch to plain text editor')->click(); foreach ($fcRow as $key => $value) { $this_row->fillField($key, $value); } $field_collection_region->findButton('Add another item')->click(); $this->iWaitForAjaxToFinish(); $row++; } } }