从预填充的列表中选择一个选项的操作如下:
$selector = "select[name='tags']";
$this->tester->openSelect2($selector);
$this->tester->selectOptionForSelect2($selector, array('text' => $tag));
$this->tester->closeSelect2($selector);
找到这个要点https://gist.github.com/tortuetorche/412fbac4f17db5e78e79.
问题是我的select2也有动态标签。(https://select2.org/tagging)
有没有人知道如何使用codeception创建动态标签?谢谢。
通常我使用WebDriver Keys
类来测试动态选择字段。
要填充dynamics select2输入,你可以这样做:
// Fill your dynamic tag with the option you want to search
$I->fillField($selector, 'Orang');
// Then, wait for the option is loaded
$I->waitForText('Orange', 30);
// Finaly, use WebDriverKeys to select the option
$I->pressKey($selector, FacebookWebDriverWebDriverKeys::ENTER);
也可以选择多个选项