Java – how to wait for a page refresh in selenium

This is an extension of my previous question unable to understand on getting the value

The situation here is as follows

The results will vary according to the postal code

At present, I have the following contents in the document

99546
60089

My code is as follows

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

    }
}

Expected results:

99546   No Results Found
Find Agent Page
60089   1 Agents Found. Please scroll down to see a list of agents.

Current results:

99546   No Results Found
Find Agent Page
60089   No Results Found

Question: I am using the following code

WebElement element = (new webdriverwait(driver,10)).until(
                            ExpectedConditions.visibilityOfElementLocated(By.xpath("html/body/div/div[1]/div[@style='']")));

At first, the block was hidden, so I waited until it was visible. From the second time, the same block was updated instead of invisible and returned to visible This is the value retrieved from the previous submission on the first submission Please let me know how to get the updated value

thank you

Solution

Perhaps you can solve this by declaring that the original element on the page will not be on the page after refresh

>Refreshandwait or clickandwait on refresh button > assertelementnotpresent page_ specific_ Element – > check that the refresh is really performed > pause for 3000 milliseconds – > wait for the refresh to end > assertelementpresent page_ specific_ Element – > check whether the refresh is correct

The same page is actually executed and loaded

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>