0

Xpath 式を含む while ループがあります。Xpath 内で 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 を使用しています。
あなたの助けは非常に高く評価されます。

4

1 に答える 1

3

これは本当に文字列の問題です。tr[n]に置き換えますtr["+n+"]

于 2013-08-14T21:38:22.687 に答える