Unable to focus element for select2 - protractor test

Using this solution to test select2 and for some reason I am getting below error.

Any suggestion on what I should be looking for?

code

 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();
}

      

Mistake

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)

      

Command duration or timeout: 30 milliseconds

+3


source to share





All Articles