首页 > 解决方案 > 如何使用 codeception 测试 select2 动态标签

问题描述

从预先填充的列表中选择一个选项的工作方式如下:

$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

有没有人想出如何使用代码接收创建动态标签?谢谢。

标签: jquery-select2codeception

解决方案


通常我使用WebDriver Keys该类来测试动态 select2 字段。
要填充动态 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, \Facebook\WebDriver\WebDriverKeys::ENTER);

它也可以选择多个选项。


推荐阅读