我有一个我正在阅读的列表,我想打印到控制台。读入列表,它获得准确的计数,在这种情况下是17个名称,但只会打印其中的11个。我可以选择按字母顺序按升序或降序列出名称,它仍然只能在第11页中读取。
var myLists = element.all(By.css("[data-bind='text: name']"));
//have also tried these ways: they work however still not full list
//var myLists = element.all(by.css('.name'));
//var myLists = element.all(by.css('td.name > span'));
this.readsInRoomName = function() {
browser.driver.get('http://iplan-qa.meetingmatrix.com/Apps/CapacityChart/ACC2833/auto/auto');
browser.driver.sleep(3000);
//clicking button to make name order descending
element.all(by.css("[data-bind='text: displayName, visible: displayName']")).first().click();
element.all(by.css("[data-bind='text: displayName, visible: displayName']")).first().click();
browser.driver.sleep(3000);
//counting and printing the list
myLists.count().then(function(count) {
console.log(count);
for (var i = 0; i < count; i++) {
myLists.get(i).getText().then(function(text) {
console.log(" here are the names desc: " + text);
});
}
});
};
结果: - 提升名称:安迪沃霍尔 - 提升名称:Boardroom Pullman - 名字提升:夏加尔 - 提升名称:放松空间 - 提升名称:克里斯托 - 名字提升:大理 - 提升名称:Hundertwasser - 提升名称:Joseph Beuys - 名字提升:康定斯基 - 提升名称:莫奈 - 提升名称:Paul Klee - 提升名称: - 提升名称: - 提升名称: - 提升名称: - 提升名称: - 名字提升:
每个名称的html都是相同的,如下所示。
<div class="cc-meeting-spaces-wrapper non-selectable jspScrollable" data-bind="jScrollPane: {}" style="overflow: hidden; padding: 0px; width: 1440px;" tabindex="0">
<div class="jspContainer" style="width: 1440px; height: 336px;">
<div class="jspPane" style="padding: 0px; top: 0px; width: 1424px;">
<table id="spacesList" class="cc-meeting-spaces-list resizable theme-meeting-spaces-list" cellspacing="0">
<tbody data-bind="foreach: meetingSpaces, highlight: {}">
<!--
ko if: capacity.hasNonZero()
-->
<tr class="selected" data-bind="click: $root.showCapacity, css: { 'selected': $data === $root.selectedSpace() && !$root.capacityLoaded() }">
<td class="name">
<span data-bind="text: name">
Andy Warhol
</span>
</td>
<td class="" data-bind="text: dimensions"></td>
<td class="" data-bind="text: ceilingHeight"></td>
<td class="cc-area"></td>
<!--
ko ifnot: showCapacities
-->
<!--
/ko
-->
<!--
ko if: showCapacities
-->
<td class="cc-capacity" title="Theater" data-style="theater" data-bind="text: capacity.theater"></td>
<td class="cc-capacity" title="Classroom" data-style="classroom" data-bind="text: capacity.classroom"></td>
<td class="cc-capacity" title="Banquet" data-style="banquet" data-bind="text: capacity.banquet"></td>
<td class="cc-capacity" title="Conference" data-style="conference" data-bind="text: capacity.conference"></td>
<td class="cc-capacity" title="UShape" data-style="uShape" data-bind="text: capacity.uShape"></td>
<td class="cc-capacity" title="Hollow Square" data-style="hollowSquare" data-bind="text: capacity.hollowSquare"></td>
<td class="cc-capacity" title="Reception" data-style="reception" data-bind="text: capacity.reception"></td>
<!--
/ko
-->
</tr>
<!--
/ko
-->
<!--
ko if: capacity.hasNonZero()
-->
<tr class="" data-bind="click: $root.showCapacity, css: { 'selected': $data === $root.selectedSpace() && !$root.capacityLoaded() }">
<td class="name">
<span data-bind="text: name">
Boardroom Pullman
</span>
</td>
<td class="" data-bind="text: dimensions"></td>
<td class="" data-bind="text: ceilingHeight"></td>
<td class="cc-area"></td>
<!--
ko ifnot: showCapacities
-->
<!--
/ko
-->
<!--
ko if: showCapacities
-->
<td class="cc-capacity" title="Theater" data-style="theater" data-bind="text: capacity.theater"></td>
<td class="cc-capacity" title="Classroom" data-style="classroom" data-bind="text: capacity.classroom"></td>
<td class="cc-capacity" title="Banquet" data-style="banquet" data-bind="text: capacity.banquet"></td>
<td class="cc-capacity" title="Conference" data-style="conference" data-bind="text: capacity.conference"></td>
<td class="cc-capacity" title="UShape" data-style="uShape" data-bind="text: capacity.uShape"></td>
<td class="cc-capacity" title="Hollow Square" data-style="hollowSquare" data-bind="text: capacity.hollowSquare"></td>
<td class="cc-capacity" title="Reception" data-style="reception" data-bind="text: capacity.reception"></td>
<!--
/ko
-->
</tr>
任何帮助都会很棒我失去了
我切换到阵列中有28个名字的另一个名单,仍然只读入/打印其中的11个。
答案:
myLists.count().then(function(count) {
console.log(count);
for (var i = 0; i < count; i++) {
browser.executeScript("arguments[0].scrollIntoView();", myLists.get(i).getWebElement());
myLists.get(i).getText().then(function(text) {
console.log(text);
});
}
});
谢谢大家!
答案 0 :(得分:1)
您还可以尝试使用map()
来解析一系列文本:
myLists.map(function (elm) {
return elm.getText();
}).then(function (texts) {
console.log(texts);
});
滚动到数组中最新记录的视图也可能有所帮助:
browser.executeScript("arguments[0].scrollIntoView();", myLists.last().getWebElement());
或者,添加等待等待所有文本非空:
browser.wait(
function () {
return myLists.count().then(function (all) {
return myLists.filter(function (elm) {
return elm.getText().then(function (text) {
return text !== "";
});
}).count().then(function (filteredCount) {
return all === filteredCount;
});
});
return
},
5000
);
您还可以尝试将map()
与滚动视图结合使用:
myLists.each(function (elm) {
browser.executeScript("arguments[0].scrollIntoView();", elm.getWebElement());
}).map(function (elm) {
return elm.getText();
}).then(function (texts) {
console.log(texts);
})
答案 1 :(得分:1)
我想知道each后缀是否适用于此实例。
myLists.each(function(element, index) {
// Will print 0 First, 1 Second, 2 Third.
browser.executeScript('arguments[0].scrollIntoView()', element.getWebElement());
element.getText().then(function (text) {
console.log(index, " here are the names desc: " + text);
});
});
更新:在打印文本
之前在视图中添加了滚动条答案 2 :(得分:0)
myLists.count().then(function(count) {
console.log(count);
for (var i = 0; i < count; i++) {
browser.executeScript("arguments[0].scrollIntoView();", myLists.get(i).getWebElement());
myLists.get(i).getText().then(function(text) {
console.log(text);
});
}
});
&#13;
我需要逐行向下滚动才能使每个名称元素都可见。