If clicking a button changes anything in the page html , the reference gets lost. You have find all elements again. So change your code as below
WebElement PositionTable = driver.findElement(By.xpath('//td[2]/table/tbody/tr/td/table'))
List<WebElement> Rows = PositionTable.findElements(By.tagName('tr'))
println('No. of rows: ' + Rows.size())
Int countrow = 0
table: while(countrow<Rows.size) {
++countrow
PositionTable = driver.findElement(By.xpath('//td[2]/table/tbody/tr/td/table'))
Rows = PositionTable.findElements(By.tagName('tr'))
List<WebElement> Cols = Rows.get(i).findElements(By.tagName('td'))
Int countcol = 0
whil(countcol < Cols.size()) {
++countcol
Cols = Rows.get(i).findElements(By.tagName('td'))
if (Cols.get(j).getText().equalsIgnoreCase(ExpectedPosition)) {
Cols.get(j).findElement(By.tagName('a')).click()
WebUI.delay(5)
table: break
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…