"For"循环在使用 xpath 检查对象时不选取"if"条件



我是JS的新手,我面临着一个问题,我找不到解决方案。我正在写一个脚本来自动"清理"。使用空手道/硒的工艺

场景:

  1. 进入网页,搜索某个标准
  2. 在填充的结果中,在单个列中获取所有值。然后在同一个搜索框中,搜索从列中抓取的每个值。
  3. 在结果中,点击删除填充的结果。
  4. 有些行会抛出异常,在这种情况下,我们想要返回并尝试列值数组中的下一个项,直到所有项都被删除或剩余项都是抛出异常的项。

我到目前为止有这个:

driver.input('#searchField', ['Mobile', Key.ENTER], 200); //here I am using Karate/Selenium to enter the search criteria on the UI. 
function() {
var searchResult = false;
searchResult = driver.exists('//table//tr');
var errorPage = driver.exists('#exception');
do {
var deleteCriteria = driver.scriptAll('//table//tr//td[3]', '_.innerText'); //Here I am grabbing actual values I need to search by across the entire column and putting it in array form.
for (i = 0; i < deleteCriteria.length; i++) {
driver.input('#searchField', [deleteCriteria[i], Key.ENTER], 200);
driver.click('#deleteBtn');
driver.click('#deleteNumber');
driver.delay(10000);
if (errorPage) {
driver.back();
driver.delay(10000);
driver.back();
driver.delay(10000);
} else {
continue;
}
}
} while (searchResult);
}

问题:当异常页面显示时,IF块没有启动。脚本无法找到要再次搜索的搜索框。请建议。

PS-我明白我的"while"还不正确。问题一解决,我就去修。

代码var errorPage = driver.exists('#exception');运行一次,并存储该时刻的状态。

如果你想知道它在当前时刻是否存在,你需要重新寻找它。

if (driver.exists('#exception')) {
...
}

相关内容

最新更新