Failed: Cannot read property 'getWebElements&#

2019-09-05 14:49发布

问题:

I am new to protractor test. it seems getWebelement is missing. the version of my protector is 3.0.0. another properties are fine (such as click, evaluate ...)

browser.wait(element(by.id('some-element')).getWebElement);

or

browser.wait(element(by.id('some-element')).isPresent);

(c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\lib\element.js:754:36) at c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:720:12 at goog.async.run.processWorkQueue (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:124:15) at process._tickCallback (node.js:368:9) From: Task: at new wrappedCtr (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:2468:26) at goog.async.run.processWorkQueue (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:124:15) at process._tickCallback (node.js:368:9) From: Task: at [object Object].webdriver.WebDriver.wait (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\webdriver.js:716:21) at [object Object].to.(anonymous function) [as wait] (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\lib\protractor.js:65:25) at Object. (c:\Users\xxx\WebstormProjects\pt\spec.js:45:21) at c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:96:23 at new wrappedCtr (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\base.js:2468:26) at controlFlowExecute (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:82:18) From: Task: Run it("unknown") in control flow at Object. (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\jasminewd2\index.js:81:14) at attemptAsync (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1819:24) at QueueRunner.run (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1774:9) at QueueRunner.execute (c:\Users\xxx\AppData\Roaming\npm\node_modules\protractor\node_modules\jasmine\node_modules\jasmine-core\lib\jasmine-core\jasmine.js:1762:10)

回答1:

browser.wait(element(by.id('some-element')).isPresent());

you are missing the parenthesis after isPresent...

and after getWebElement...

browser.wait(element(by.id('some-element')).getWebElement());


回答2:

You'll need to wrap the call to isPresent() in a function, like so:

browser.wait(function() {
  return element(by.id('some-element')).isPresent();
})

so that isPresent() runs each time browser.wait calls it.