是否可以使用Protractor将for循环运行到.then中? 我试图做这样的事情:
element.all(by.css('.select2-results li')).then(function(item) {
for(i = 0; i < item.lenght; i++){
browser.actions().mouseMove(item[i]).perform();
browser.sleep(500);
}
});
但似乎Protractor忽略了for循环,你能帮帮我吗?
我曾经使用过。但是当我运行它时我得到了这个:
StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=43.0.2357.130)
(Driver info: chromedriver=2.13.307647 (5a7d0541ebc58e69994a6fb2ed930f45261f3c
29),platform=Windows NT 6.2 x86_64) (WARNING: The server did not provide any sta
cktrace information)
Command duration or timeout: 7 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/
stale_element_reference.html
Build info: version: '2.44.0', revision: '76d78cf', time: '2014-10-23 20:02:37'
System info: host: 'AVANTEK-PC01', ip: '192.168.56.1', os.name: 'Windows 8', os.
arch: 'amd64', os.version: '6.2', java.version: '1.7.0_51'
Session ID: 3f5e0df8acf94705c936176f21bb05bd
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{platform=WIN8, acceptSslCerts=true, javascriptEnabled=true, brows
erName=chrome, chrome={userDataDir=C:\Users\MARCEL~1.ORT\AppData\Local\Temp\scop
ed_dir208_14914}, rotatable=false, locationContextEnabled=true, mobileEmulationE
nabled=false, version=43.0.2357.130, takesHeapSnapshot=true, cssSelectorsEnabled
=true, databaseEnabled=false, handlesAlerts=true, browserConnectionEnabled=false
, webStorageEnabled=true, nativeEvents=true, applicationCacheEnabled=false, take
sScreenshot=true}]
我使用的代码是:
element.all(by.css('.select2-results li')).each(function(elm) {
browser.actions().mouseMove(elm).perform();
browser.sleep(500);
var el = elm.getAttribute('class');
expect(el).toContain('select2-results-dept-0 select2-result select2-result-selectable select2-highlighted');
expect(elm.getCssValue('background-color')).toEqual('rgba(114, 101, 91, 1)');
elm.click();
});
答案 0 :(得分:0)
使用each()
,而不是for循环,更具“原型”解决方案:
在ElementArrayFinder表示的每个ElementFinder上调用输入函数。
element.all(by.css('.select2-results li')).each(function(elm) {
browser.actions().mouseMove(elm).perform();
browser.sleep(500);
});