gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 17:51:26 24 4
gpt4 key购买 nike

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

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");
}

关于java - 有没有办法检查是否使用 WebDriver (java) 重新加载了元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44498255/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com