使用此solution来测试select2,由于某种原因,我在下面收到错误。
关于我应该看什么的任何建议?
代码
this.select2First = function(select2Locator, opt_query) {
// the 'a' element inside the select2 will receive the 'mousedown' event
var selector = select2Locator + ' a.select2-choice select2-default';
// Locator for the select2 options
var options = element.all(by.css('.select2-results-dept-0'));
// select2 doesn't activate on click
// and protractor doesn't have a direct mousedown method on 'ElementFinder'.
browser.driver.executeScript('$(arguments["0"]).mousedown();', (selector));
if (opt_query) {
browser.driver.switchTo().activeElement().sendKeys(opt_query);
// select2 can fetch options from over a network
// so we confirm that all pending network requests are resolved after typing the query
browser.driver.wait(function () {
return browser.driver.executeScript('return $.active === 0;');
}, 2000);
}
// makes sure all the options are rendered
browser.driver.wait(function () {
return options.count().then(function (count) {
return 0 < count;
});
}, 2000);
options.first().click();
}
错误
UnknownError: unknown error: cannot focus element
(Session info: chrome=42.0.2311.135)
(Driver info: chromedriver=2.14.313457(3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.3 x86_64) (WARNING: The server did not provide any stacktrace information)
命令持续时间或超时:30毫秒