我有一个包含Xpath表达式的while循环。如何只在trpath中更改tr [index]的值,才能使while循环正常工作?以下是一个例子:
//this is what I currently have:
while(webDriver.findElement(By.xpath("//*[@id='sharing_list']/tbody/tr[1]/td[4]")).isDisplayed())
{
webDriver.findElement(By.xpath("//*[@id='sharing_list']/tbody/tr[1]/td[4]/span")).click();
}
//and this is what I would like to have:
int n=1;
while(webDriver.findElement(By.xpath("//*[@id='sharing_list']/tbody/tr[n]/td[4]")).isDisplayed())
{
webDriver.findElement(By.xpath("//*[@id='sharing_list']/tbody/tr[n]/td[4]/span")).click();
n++;
}
有人知道如何让它发挥作用吗?我使用的是Selenium 2.33 非常感谢您的帮助。
答案 0 :(得分:3)
这确实是一个String问题。将tr[n]
替换为tr["+n+"]