Reputation: 91
I have a register form, which is filled by Selenium Webdriver, it submits and goes to the post registration page. Upon checking the URL with driver.getCurrentUrl() the previous page url is returned.
driver.get(baseUrl + "home") // url /home
driver.findElement(By.id(<<button>>).click(); // url -> /register
driver.findElement(By.id(<<textfield>>).sendKeys("the entire form is filled"); // url /register
driver.findElement(By.id(<<submit button>>).click(); // url -> /postRegister
System.out.println(driver.getCurrentUrl()); //
result: url /register
Expected: url /postRegister
Upvotes: 0
Views: 1307
Reputation: 1484
Did you put some wait after click, and tried getCurrentURL()? driver.findElement(By.id(<>).click(); // url -> /postRegister. Thread.Sleep(10000); //put some suitable wait or atleast it tries to navigate to post register page. System.out.println(driver.getCurrentUrl());
Upvotes: 0
Reputation: 3649
This shouldn't be happening but anyhow you can use JavascriptExecutor to fetch the current url as:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return window.location.href").toString();
Upvotes: 2