我需要检查 3 个元素中的哪一个包含文本“10%”,但我不确定我是否正确获取了该元素的文本。当我运行代码时,我没有收到错误,但 if 条件始终为 false(当它应该为 true 时)。
我在规范中的 javascript 代码:
await driver.wait(until.elementIsVisible(await driver.findElement(By.css("tr:nth-child(1) .font-weight-bold-light > span"))), 30000)
await driver.wait(until.elementIsVisible(await driver.findElement(By.css("tr:nth-child(2) .font-weight-bold-light > span"))), 30000)
await driver.wait(until.elementIsVisible(await driver.findElement(By.css("tr:nth-child(3) .font-weight-bold-light > span"))), 30000)
var array = ["tr:nth-child(1) .font-weight-bold-light > span", "tr:nth-child(2) .font-weight-bold-light > span", "tr:nth-child(2) .font-weight-bold-light > span"];
var arrayDelete = ["tr:nth-child(1) img:nth-child(2)", "tr:nth-child(2) img:nth-child(2)", "tr:nth-child(3) img:nth-child(2)"]
for (var k = 0; k<array.length; k++){
var allOpts = (await driver.findElement(By.css(array[k])));
await driver.sleep(2000)
if (allOpts == ('10%')) {
await driver.sleep(2000)
await driver.wait(until.elementIsVisible(await driver.findElement(By.css(arrayDelete[k]))), 30000)
// 11 | click | css=.actions > img:nth-child(2) |
await driver.findElement(By.css((arrayDelete[k]))).click()
// 12 | pause | 1000 |
await driver.sleep(5000)
// 13 | waitForElementVisible | css=.ml-3 | 30000
await driver.wait(until.elementIsVisible(await driver.findElement(By.css(".ml-3"))), 30000)
// 14 | click | css=.ml-3 |
await driver.findElement(By.css(".ml-3")).click()
// 15 | pause | 3000 |
await driver.sleep(10000)
// 16 | verifyElementNotPresent | css=td:nth-child(1) |
{
const elements = await driver.findElements(By.css((allOpts)))
assert(!elements.length)
}
console.log(('ho cancellato l obiettivo ')+ k);
} else {
console.log(('obiettivo ') + k + (' non cancellato, in quanto il suo peso non è 10%'));
}
}
白衣非少年
桃花长相依
慕后森
相关分类