java – 如何在Selenium中等待页面刷新
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – 如何在Selenium中等待页面刷新,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3184字,纯文字阅读大概需要5分钟。
内容图文
![java – 如何在Selenium中等待页面刷新](/upload/InfoBanner/zyjiaocheng/746/ffe28ee99faa43deb6a3299a3971b69d.jpg)
这是我之前的问题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='']")));
最初,这个块是隐藏的,所以我等到它可见,从第二次开始,相同的块被更新而不是看不见并返回可见.
这是在第一次提交时从上一次提交中检索的值.
请让我知道如何获取更新的值.
谢谢
解决方法:
也许,您可以通过声明页面上最初存在的元素在刷新后不在页面上来解决它
> refreshAndWait或clickAndWait on refresh button
> assertElementNotPresent page_specific_element – >检查刷新
真的被执行了
>暂停3000毫秒 – >等待刷新结束
> assertElementPresent page_specific_element – >检查刷新是否
真正执行并且已加载相同的页面
内容总结
以上是互联网集市为您收集整理的java – 如何在Selenium中等待页面刷新全部内容,希望文章能够帮你解决java – 如何在Selenium中等待页面刷新所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。