2
我正在創建一個自動化框架,我需要從元素中獲取值並將其與預先收集的值進行匹配。現在,問題是,在加載頁面後,div值會更新,所以即使在添加隱式等待/流暢等待/ Thread.sleep後,代碼也不起作用。 但是,當我調試代碼時,代碼正常工作,沒有做任何改變。我不知道必須做什麼。在Selenium測試中找不到元素當div元素在頁面加載後重新加載
由於我是一個新用戶,我不能在這個問題中添加圖片,但最初的 「total:value」是「總數:0」,並且它需要一段時間才能填充,因此它會發生變化,但是由於預先加載了頁面超時不起作用。
請提出建議。
String sID = oIPops.getLocator("<value from properties file>");
/*
WebDriverWait wait = new WebDriverWait(driver,40);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(sID)));
*/
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String tValue = driver.findElement(By.id(sID)).getText();
System.out.println(""+tValue); // it will print Total : <populated value>
// Extracting the number from the string to match with data I have beforehand
char num = tValue.charAt(7);
String character = "+" + num;
Integer newNum = new Integer(character);
if (value == newNum)
{
logger.info("Sum of Situations on Cluster "+title+ " matches with the total value from situation table");
}
else
{
logger.error("Sum of Situations on Cluster "+title+ " does not match with the total value from situation table");
}
id = sID的元素是否從html的開頭存在,或者是以後注入的整個元素?如果是這樣,它只會改變一次嗎?最後,它在靜態HTML中以某種方式初始化? – luksch
每次頁面加載時,值是否都會更改?我的意思是,你能否明確地等待價值改變,然後才能得到它? –
該元素從默認值0開始存在,實際值稍後注入。因此它只能更改一次,但這取決於刷新頁面或填充id值的表被刷新。我確實嘗試了明確的等待,但它不起作用,正如我上面提到的。 – Avataar17