でページの更新を待つにはどうすればよいこれが私の前の質問ここで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='']")));
最初は、このブロックは、それが見えるまで、私は二回目から、待っているように隠されている、同じブロックではなく、目に見えないだろうと戻って見えてくるの更新されます。 これは、最初のサブミット時に前のサブミットから取得された値です。 更新された値を取得する方法を教えてください。更新ボタン上
おかげ
私はあなたが '' make paus 'に 'Thread.sleep(4000)'メソッドを使うことができると思います。 eを数秒間(適切な解決策ではありません)スクリプトで一時停止することでテキストを取得できます。 – NarendraR