如何在内部框架中执行带有循环的代码块
How can execute a block of code with loops into the intern framework
我使用selenium的内部框架,我想执行一个查找表中元素的循环。循环查找每个元素并将其保存在数组中,获取元素后再进行操作。
思路是:
browser.wait(2000)
.then(function () {
while (true) {
ifHasElements=browser.isDisplayed("/html/body/div[1]/div[5]/div[3]/div/div[3]/div[1]/table[2]/tbody/tr["+contRowsTable+"]").end()
if (ifHasElements) {
console.log("into if")
browser.elementByXPath("/html/body/div[1]/div[5]/div[3]/div/div[3]/div[1]/table[2]/tbody/tr["+contRowsTable+"]/td[1]")
.clickElement()
.end()
rows[contRowsTab]=browser.elementByXPath("/html/body/div[1]/div[5]/div[3]/div/div[3]/div[1]/table[2]/tbody/tr["+contRowsTable+"]")
} else {
break
}
contRowsTab++;
contRowsTable++;
}
})
我不知道我是否执行了一个循环,同时在then块中获取元素。谁能帮我这个,非常感谢。
试试这样写:
var visibleRows = [];
var stopStoring = false;
return browser
.wait(2000)
.then(function () {
return this.parent
// find all the rows
.findAllByXpath('/html/body/div[1]/div[5]/div[3]/div/div[3]/div[1]/table[2]/tbody/tr')
.then(function (rows) {
// store the visible rows until the first non-visible row is encountered
return rows.reduce(function (chain, row) {
return chain.then(function () {
return row
.isVisible()
.then(function (isVisible) {
if (!isVisible) {
stopStoring = true;
}
if (isVisible && !stopStoring) {
visibleRows.push(row);
}
});
});
}, this.parent);
})
.then(function () {
// for each visible row, click the first td in the row
return visibleRows.reduce(function (chain, row) {
return chain
.findByXpath('./td[1]')
.click()
.end();
}, this.parent);
});
});
在这段代码中,我首先找到并存储可见行的第一个连续运行。然后,对于每一行,单击该行中的第一个表格单元格。
相关文章:
- 如何将数组循环到JSON代码中
- 创建一个循环来简化HTML和CSS代码
- 未执行Ajax循环的Javascript之后的代码
- javascript代码不会在循环后执行
- 可能只在for循环内部运行一次代码块
- 在循环中分析云代码查询
- 如何在javascript循环中打印代码
- GraphQL代码中的Javascript循环依赖关系
- 循环中的多个查询分析云代码
- 使用从forEach循环中提取的国家代码从数组中获取国家名称
- 停止代码,直到 AJAX 调用在 $.each 循环中完成
- Javascript代码中断循环
- 我在jquery上的循环代码;不要在循环中使用
- 如何分解循环代码以创建大型应用程序
- 对于未显示的循环代码
- 在for循环代码后调用javascript函数
- 我应该如何修复我的for循环代码求和范围
- 简单循环通过一个数组;对于";循环代码令人困惑
- 是否有一种方法可以检测事件循环代码运行在哪个回合
- 在. js文件中编写php while循环代码