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