这是迭代动态表的代码。
driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
console.log("NoofRowsinthetable" + rows.length);
var identifyvalue = "6/16/17 12:41 PM"
var datacount = 0;
for (var i = 1; i <= rows.length; i++) {
driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td`)).then(function (cells) {
console.log("NoofColumnsinthetable" + cells.length);
for (var j = 1; j <= cells.length; j++) {
driver.findElement(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[i]/td[j]`)).getText().then(function (cell_text) {
console.log(cell_text);
if (identifyvalue === cell_text) {
datacount = datacount + 1;
console.log("Data count" + datacount);
}
})
First Forloop: 即使有9列,Cells.length也会返回零。
如果我正在传递我作为弦乐的价值(tr [“+ i +”])那么它只会返回第一行的长度,如果我没有通过'我'作为弦乐的价值然后,它正在退回专栏。长度为零。
Second For循环: 如果我通过I和J作为字符串的值(tr [“+ i +”] / td [“+ j +”]),那么它只返回第一列的值
答案 0 :(得分:0)
问题在于单引号。你是用单引号开始字符串,它应该以单一结束。尝试以下,
driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr`)).then(function(rows) {
console.log("NoofRowsinthetable" + rows.length);
var identifyvalue = "6/16/17 12:41 PM"
var datacount = 0;
for (var i = 1; i <= rows.length; i++) {
driver.findElements(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td`)).then(function (cells) {
console.log("NoofColumnsinthetable" + cells.length);
for (var j = 1; j <= cells.length; j++) {
driver.findElement(By.xpath(`//*[@id="slide-wrapper"]/div/ui-view/search-activities/div/div[2]/table/tbody/tr[`+i+`]/td[`+j+`]`)).getText().then(function (cell_text) {
console.log(cell_text);
if (identifyvalue === cell_text) {
datacount = datacount + 1;
console.log("Data count" + datacount);
}
})