當訪問存儲返回值「elements.all」的變量時,我遇到了量角器出現問題。我對Protractor相當陌生,所以我不確定如何通過自定義屬性選擇元素。幸運的是,當我在另一篇文章中發佈question時,我收到了一條建議。我被建議嘗試 - 「element.all(by.css('[mycustom-id]'));」。但我不知道這個聲明是否有效,因爲我得到「無法找到元素的可測性」錯誤。也有可能我錯誤地迭代了這個對象。我很感激你們有沒有人能指出我的錯誤。謝謝。量角器 - 在訪問元素時給予「找不到元素的可測性」錯誤
Spec.JS
var settings = require(__dirname + '/setting.json');
describe('Protractor Demo App', function() {
var target = element.all(by.css('[mycustom-id]'));
beforeEach(function() {
browser.get(settings.url);
});
it('Test mouseover', function() {
// This does not work
target.each(function(item){
//Do some stuff here
});
// This does not work either
target.count().then(function(x){
console.log("Total--" + x);
});
});
});
的index.html
<div>
<a mycustom-id="123" href=''>HELLO1</a>
<a mycustom-id="211" href=''>HELLO2</a>
</div>
我也嘗試過,但每次訪問「目標」時仍然「無法找到元素的可測試性」。感謝您的回覆。 – user30646
有趣。這個錯誤是否給出了一段不合法的代碼,它是否是'it()'塊?我懷疑browser.get() – Gunderson
它可能來自「target.each」行。因爲只要我註釋掉該行,錯誤就消失了。它只是不讓我訪問「目標」 – user30646