簡體   English   中英

Selenium:如何在 for 循環中獲取 webelement 的變化值

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM