java到时间刷新页面_java – 如何在Selenium中等待页面刷新

这是我之前的问题

Unable to understand on getting the value的扩展

这里的情况如下.

根据邮政编码,结果会有所不同.

目前我在文件中有以下内容.

99546

60089

我的代码如下.

import java.io.BufferedReader;

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.IOException;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.firefox.FirefoxDriver;

import org.openqa.selenium.remote.CapabilityType;

import org.openqa.selenium.remote.DesiredCapabilities;

import org.openqa.selenium.support.ui.ExpectedConditions;

import org.openqa.selenium.support.ui.WebDriverWait;

public class Test1 {

public static void main(String[] args) throws InterruptedException, FileNotFoundException {

WebDriver driver;

System.setProperty("webdriver.gecko.driver", "C:\\Users\\home\\Downloads\\geckodriver.exe");

DesiredCapabilities capabilities = new DesiredCapabilities();

capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);

driver = new FirefoxDriver(capabilities);

driver.get("https://www2.chubb.com/us-en/find-agent-page.aspx");

try {

File file = new File("zip.txt");

FileReader fileReader = new FileReader(file);

BufferedReader bufferedReader = new BufferedReader(fileReader);

StringBuffer stringBuffer = new StringBuffer();

String line;

while ((line = bufferedReader.readLine()) != null) {

driver.findElement(By.xpath(".//*[@id='tbAddress']")).clear();

driver.findElement(By.xpath(".//*[@id='cphHeroContent_drpDistanceMiles']")).sendKeys("Select Distance");

driver.findElement(By.xpath(".//*[@id='tbAddress']")).sendKeys(line);

driver.findElement(By.xpath(".//*[@id='cphHeroContent_drpDistanceMiles']")).sendKeys("2");

driver.findElement(By.xpath(".//*[@id='cphHeroContent_rdType_0']")).click();

driver.findElement(By.xpath(".//*[@id='cphHeroContent_btnSearch']")).click();

String title = driver.getTitle().toString();

System.out.println(title);

WebElement element = (new WebDriverWait(driver, 10)).until(

ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/div/div[1]/div[@style='']")));

String getHeadingTitle = element.getText();

System.out.println(line + "\t" + getHeadingTitle);

}

fileReader.close();

System.out.println("Contents of file:");

System.out.println(stringBuffer.toString());

} catch (IOException e) {

e.printStackTrace();

}

}

}

预期结果:

99546 No Results Found

Find Agent Page

60089 1 Agents Found. Please scroll down to see a list of agents.

目前的结果:

99546 No Results Found

Find Agent Page

60089 No Results Found

问题:

我正在使用以下代码.

WebElement element = (new WebDriverWait(driver, 10)).until(

ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/div/div[1]/div[@style='']")));

最初,这个块是隐藏的,所以我等到它可见,从第二次开始,相同的块被更新而不是看不见并返回可见.

这是在第一次提交时从上一次提交中检索的值.

请让我知道如何获取更新的值.

谢谢

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值