JavaでSelenium Webdriverを使用しています。「次へ」ボタンをクリックしてページ1からページ2に移動した後、現在のURLを取得したい.これが私が持っているコードです:
WebDriver driver = new FirefoxDriver();
String startURL = //a starting url;
String currentURL = null;
WebDriverWait wait = new WebDriverWait(driver, 10);
foo(driver,startURL);
/* go to next page */
if(driver.findElement(By.xpath("//*[@id='someID']")).isDisplayed()){
driver.findElement(By.xpath("//*[@id='someID']")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='someID']")));
currentURL = driver.getCurrentUrl();
System.out.println(currentURL);
}
現在の URL を取得する前に、ページが完全に読み込まれるまで待機する暗黙的および明示的な待機呼び出しの両方があります。ただし、ページ 1 の URL はまだ出力されています (ページ 2 の URL であると予想されます)。