[英]Selenium: How to get the changing value of a webelement in a for loop
我試圖獲得隨時間變化的 weblement 價值。 值為 - Pending, Approved, Received
。
當值更改為Received
時,我必須停止循環。 我嘗試了下面的代碼,但它在一個循環中成功運行,然后在第二個循環中停止,錯誤是webelement not found with the given xpath
。
for(int i=0;i<=50;i++)
{
String exactvalue=driver.findElement(By.xpath("//tr[2]/td")).getText();
if (exactvalue.equals("Received"))
{
break;
}
else
{
driver.navigate().refresh();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
throw new RuntimeException("executing sleep interrupted");
}
}
}
從您的代碼中替換下面的行。
你的代碼:
String exactvalue=driver.findElement(By.xpath("//tr[2]/td")).getText();
用。。。來代替 :
String exactvalue=driver.findElement(By.xpath("//tr["+i+"]/td")).getText();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.