最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS Protractor element by.model can't find element? - Stack Overflow

programmeradmin2浏览0评论

using the element(by.model()) syntax to find a field and input text.

element(by.model('sample_ad.id')).sendKeys('batman');

gets the exception from chromedriver:

Stacktrace:
     Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds
    at Error (<anonymous>)
==== async task ====
WebDriver.executeScript()
    at Protractor.waitForAngular (/Users/jon/dev/project_name/node_modules/protractor/lib/protractor.js:278:22)
    at Protractor.findElement (/Users/jon/dev/project_name/node_modules/protractor/lib/protractor.js:427:8)
    at Object.elementFinder.(anonymous function) [as sendKeys] (/Users/jon/dev/project_name/node_modules/protractor/lib/protractor.js:62:21)
    at null.<anonymous> (/Users/jon/dev/project_name/test/e2e/features/somedirectiveSpec.js:24:39)
    at /Users/jon/dev/project_name/node_modules/protractor/jasminewd/index.js:54:12
==== async task ====
    at null.<anonymous> (/Users/jon/dev/project_name/node_modules/protractor/jasminewd/index.js:53:12)
    at null.<anonymous> (/Users/jon/dev/project_name/node_modules/protractor/node_modules/minijasminenode/lib/async-callback.js:45:37)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Not sure why this is breaking, but Protractor seems very fragile right now... I have no issues using the browser object to find elements, input text, etc...

Any help would be appreciated

EDIT: if I change the line to the following, I am able to interact with the text field. browser.driver.findElement(protractor.By.id('sample_ad_id')).sendKeys('batman');

using the element(by.model()) syntax to find a field and input text.

element(by.model('sample_ad.id')).sendKeys('batman');

gets the exception from chromedriver:

Stacktrace:
     Error: Timed out waiting for Protractor to synchronize with the page after 11 seconds
    at Error (<anonymous>)
==== async task ====
WebDriver.executeScript()
    at Protractor.waitForAngular (/Users/jon/dev/project_name/node_modules/protractor/lib/protractor.js:278:22)
    at Protractor.findElement (/Users/jon/dev/project_name/node_modules/protractor/lib/protractor.js:427:8)
    at Object.elementFinder.(anonymous function) [as sendKeys] (/Users/jon/dev/project_name/node_modules/protractor/lib/protractor.js:62:21)
    at null.<anonymous> (/Users/jon/dev/project_name/test/e2e/features/somedirectiveSpec.js:24:39)
    at /Users/jon/dev/project_name/node_modules/protractor/jasminewd/index.js:54:12
==== async task ====
    at null.<anonymous> (/Users/jon/dev/project_name/node_modules/protractor/jasminewd/index.js:53:12)
    at null.<anonymous> (/Users/jon/dev/project_name/node_modules/protractor/node_modules/minijasminenode/lib/async-callback.js:45:37)
    at Timer.listOnTimeout [as ontimeout] (timers.js:110:15)

Not sure why this is breaking, but Protractor seems very fragile right now... I have no issues using the browser object to find elements, input text, etc...

Any help would be appreciated

EDIT: if I change the line to the following, I am able to interact with the text field. browser.driver.findElement(protractor.By.id('sample_ad_id')).sendKeys('batman');

Share Improve this question edited Jan 9, 2014 at 0:09 jonh asked Jan 8, 2014 at 21:38 jonhjonh 2423 silver badges10 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 3

hopefully this will help others....

Found this on github (see references link). The issue I believe is a script not returning, thus the sendKeys didn't work. Before interacting with the dom using protractor objects (element, ptor, etc), set this variable:

browser.ignoreSynchronization = true;

The reason the following works is because it doesn't rely on async calls, its just directly interacts with the dom and inserts the keys into the input field. browser.driver.findElement(protractor.By.id('sample_ad_id')).sendKeys('batman');

The reason my call didn't work (I believe) is because there was an async call that didn't return in time.
element(by.model('sample_ad.id')).sendKeys('batman');

references: https://github./angular/protractor/issues/325

See https://github./angular/protractor/blob/master/docs/faq.md#my-tests-time-out-in-protractor-but-everythings-working-fine-when-running-manually-whats-up

for more information on timeouts.

It looks like your test is timing out. The default timeout for protractor is 11 seconds.

Try setting a different timeout for this test:

it('should override timeout', function() {
  // Timeout of 30 seconds.
  element(by.model('sample_ad.id')).sendKeys('batman');
}, 30000)

You can also override the timeout for all your tests in the protractor configuration file. See this sample config file:

https://github./andresdominguez/protractor-meetup/blob/master/protractor-config.js#L19

// Inside the protractor config file.
onPrepare: function() {
  // Override the timeout for webdriver.
  var ptor = protractor.getInstance();
  ptor.driver.manage().timeouts().setScriptTimeout(60000);
}
发布评论

评论列表(0)

  1. 暂无评论