有没有办法检查元素是否用WebDriver(java)重新加载?

有没有办法检查元素是否用WebDriver(java)重新加载?,java,selenium-webdriver,Java,Selenium Webdriver,我需要在每次更新后验证一个元素。例如:Lowrtemperature:7.54经过一段时间后,该值将更改为Lowrtemperature:3.79,然后更改为其他值。每次经过一段时间(时间不同)后,该值将更改。但是我需要驱动程序在更改后获取更新的值。如何使用SeleniumWebDriver获取元素,这里页面没有重新加载,只有元素值被重新加载 public boolean waitForTextToChange(WebElement element, String currentText) {

我需要在每次更新后验证一个元素。例如:Lowrtemperature:7.54经过一段时间后,该值将更改为Lowrtemperature:3.79,然后更改为其他值。每次经过一段时间(时间不同)后,该值将更改。但是我需要驱动程序在更改后获取更新的值。如何使用SeleniumWebDriver获取元素,这里页面没有重新加载,只有元素值被重新加载

public boolean waitForTextToChange(WebElement element, String currentText) {
                return !element.getText().equals(currentText);
            }


public String Lowertemperature_14_L(){
    WebElement element = driver.findElement(By.xpath(".//*[@id='webForm:sensorContainer']/div[@class='tile tile23 show-all hide-tiny']/div[@class='meteo-line1']/div[1]/div[@class='icon']/div[@class='icon-label0']"));
   String currentText = element.getText();
   WebDriverWait wait = new WebDriverWait(driver, 10);
   wait.until(waitForTextToChange(element, currentText));
   return currentText;
   }

//此处,第一个值为ex.4.56,20秒后,该值更新为3.67,然后每隔20秒更新一次(时间在8、10、6等之后变化一段时间)。我使用wait.until(Expectedconditions.stalenessOf(element))检查值是否更新,然后我们从ui获得一个新的更新值,并在更新值之前和之后进行验证

 wait = new WebDriverWait(driver, 20);
                By container = By.xpath(".//*[@id='webForm:sensorContainer']/div/div[1]/div[1]/div/div[6]");
                wait.until(ExpectedConditions.visibilityOfElementLocated(container));

                /* Read the text that appears in the XPath text control. */
                WebElement ajaxControl = driver.findElement(container);
                String ajaxTextFirstPara = ajaxControl.getText().trim();

                WebElement ele= driver.findElement(container);
                try{
                       wait.until(ExpectedConditions.stalenessOf(ele));
                }catch(TimeoutException e){
                }

                /* Wait for the new content to appear in the xpath text control. */
                By newAjaxcontrol =  container;
                Wait<WebDriver> newwait = new FluentWait<>(driver)
                        .withTimeout(60, TimeUnit.SECONDS)
                        .pollingEvery(5, TimeUnit.SECONDS)
                        .ignoring(NoSuchElementException.class);
                newwait.until(ExpectedConditions
                        .visibilityOfElementLocated(newAjaxcontrol));
                WebElement undergroundTemperature_14_L_value= driver.findElement(newAjaxcontrol);
                String undergroundTemperature_14_L =undergroundTemperature_14_L_value.getText().trim();
                if(ajaxTextFirstPara!= undergroundTemperature_14_L)
                {
                    System.out.println("diffeerent");
                }else{
                    System.out.println("same");
                }
wait=newwebdriverwait(驱动程序,20);
By container=By.xpath(“./*[@id='webForm:sensorContainer']/div/div[1]/div[1]/div/div[6]”);
等待。直到(预期条件。位于(容器)的元素的可视性);
/*读取XPath文本控件中显示的文本*/
WebElement ajaxControl=driver.findElement(容器);
字符串ajaxTextFirstPara=ajaxControl.getText().trim();
WebElement ele=driver.findElement(容器);
试一试{
等待.直到(预期条件.过时的(ele));
}捕获(超时异常e){
}
/*等待新内容出现在xpath文本控件中*/
按newAjaxcontrol=容器;
Wait newwait=new FluentWait(驱动程序)
.带超时(60,时间单位。秒)
.轮询间隔(5,时间单位。秒)
.忽略(NoSuchElementException.class);
newwait.until(预期条件
.位于(newAjaxcontrol)的元素的可视性;
WebElement undergroundTemperature\u 14\u L\u value=driver.findElement(newAjaxcontrol);
字符串underroundTemperature_14_L=underroundTemperature_14_L_value.getText().trim();
如果(ajaxTextFirstPara!=地下温度)
{
System.out.println(“不同”);
}否则{
系统输出打印项次(“相同”);
}

低温:7.54
是文本吗?或者其他什么?是的,它是文本,但只有值更改,而不是Lowertemperature@Guy我在代码处得到错误:wait.until(waitForTextToChange(element,currentText));错误:FluentWait类型中的方法until(谓词)不适用于参数(布尔值),我添加了guava library 21版本,但我仍然在wait.until中收到错误