量角器 - 无法从下拉角度列表中选择项目

时间:2016-01-18 13:50:26

标签: jquery angularjs selenium-webdriver jasmine protractor

我尝试通过Angular下拉列表选择第二项,但是webdriver没有找到此元素。

错误:

NoSuchElementError: No element found using locator: By.cssSelector("[ng-click=\"setCustomMode()\"]") at new bot.Error (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\atoms\error.js:113:18) at C:\automation\npm\node_modules\protractor\lib\element.js:706:15 at [object Object].promise.ControlFlow.runInFrame_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.Callback_.goog.defineClass.notify (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2464:25) at [object Object].promise.Promise.notify_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:563:12) at Array.forEach (native) at Object.goog.array.forEach (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\array\array.js:203:43) at [object Object].promise.Promise.notifyAll_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:552:16) at goog.async.run.processWorkQueue (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) at runMicrotasksCallback (node.js:337:7) Error at [object Object].ElementArrayFinder.applyAction_ (C:\automation\npm\node_modules\protractor\lib\element.js:403:21) at [object Object].self.(anonymous function) [as isDisplayed] (C:\automation\npm\node_modules\protractor\lib\element.js:76:19) at [object Object].self.(anonymous function) [as isDisplayed] (C:\automation\npm\node_modules\protractor\lib\element.js:733:11) at [object Object]. (C:\automation\tests\testCases\newApp\newBtnTC.js:111:16) at C:\automation\npm\node_modules\protractor\node_modules\jasminewd\index.js:94:14 at [object Object].promise.ControlFlow.runInFrame_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1877:20) at [object Object].promise.ControlFlow.runEventLoop_ (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:1755:8) at [object Object]. (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\webdriver\promise.js:2056:12) at goog.async.run.processWorkQueue (C:\automation\npm\node_modules\protractor\node_modules\selenium-webdriver\lib\goog\async\run.js:125:21) at runMicrotasksCallback (node.js:337:7) From: Task: Asynchronous test function: it() at [object Object]. (C:\automation\npm\node_modules\protractor\node_modules\jasminewd\index.js:93:33) at [object Object]. (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\async-callback.js:45:37) at [object Object].jasmine.Block.execute (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:1174:17) at [object Object].jasmine.Queue.next_ (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) at [object Object].jasmine.Queue.start (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2162:8) at [object Object].jasmine.Spec.execute (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2503:14) at [object Object].jasmine.Queue.next_ (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2209:31) at onComplete (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2205:18) at [object Object].jasmine.Spec.finish (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2477:5) at [object Object].onComplete (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:2504:10)==== async task ==== Error at [object Object]. (C:\automation\tests\testCases\newApp\newBtnTC.js:110:4) at [object Object].jasmine.Env.describe_ (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:913:21) at [object Object].jasmine.Env.describe (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:898:15) at describe (C:\automation\npm\node_modules\protractor\node_modules\minijasminenode\lib\jasmine-1.3.1.js:658:27) at Object. (C:\automation\tests\testCases\newApp\newBtnTC.js:1:63) at Module._compile (module.js:460:26) at Object.Module._extensions..js (module.js:478:10) at Module.load (module.js:355:32) at Function.Module._load (module.js:310:12)

1 个答案:

答案 0 :(得分:0)

问题在于这一行:

browser.wait(EC.visibilityOf($$("k-list-container.k-popup.k-group.k-reset")), 30000);

visibilityOf预期条件需要传入ElementFinder。使用:

browser.wait(EC.visibilityOf($("k-list-container.k-popup.k-group.k-reset")), 30000);

另外,我认为你在选择器的开头缺少点,因为k-list-container是其中一个类:

.k-list-container.k-popup.k-group.k-reset

而且,即使是固定选择器也不会起作用。以下是对我有用的内容:

element(by.model("selectedService")).click().then(function () {
    browser.wait(EC.visibilityOf($("md-select-menu md-option")), 30000);
    $$("md-select-menu md-option").get(1).click();
    browser.driver.sleep(2000);
});