我一直在尝试解决我面临的问题,但我没有想法,所以我需要帮助。
我有一个非常简单的页面:
╔════════════════════════════╦═══════════════════════════════════════╗
║ RoleName ║ Delete ║
╠════════════════════════════╬═══════════════════════════════════════╣
║ ABC1 (index starts with 1) ║ [delete button] (index starts with 0) ║
║ ABC2 ║ [delete button] ║
║ ABC3 ║ [delete button] ║
║ ABC4 ║ [delete button] ║
║ ABC5 ║ [delete button] ║
╚════════════════════════════╩═══════════════════════════════════════╝
这是自动化它的代码:
//count how many rows avaiable
IList<IWebElement> count = driver.FindElements(By.CssSelector("div#ctl00_MainContent_divUserInfo"));
//note: starting with 1 since the RoleName colum starts with 1 (html code render on the page)
for (int i = 1; i <= count.Count; i++)
{
string selName = string.Empty;
selName = String.Format("div#ctl00_MainContent_divUserInfo tr.item:nth-of-type({0}) > td a#aDetail:nth-child(1)", i);
string selNameText = TextByCssSelector(selName);
bool isNameExists = Names.Any(s => selNameText.Equals(s.Value.ToString(), StringComparison.OrdinalIgnoreCase));
if (isNameExists)
{
//if found then click on delete button to remove the item....
}
}
上面的代码按我预期的那样工作,但是有一个问题,问题是如果我删除该行而不是发生以下事情:
- 页面重新渲染页面
- 我得到了一组新的计数
但请记住,我仍在 中for-loop
,所以我的计数是基于以前的(在我删除该行之前)我的问题是:
我应该如何处理这种情况?