I am using Selenium Java WebDriver to create my tests. The test I'm trying to automate is as follows: 1) Get URL from CSS Element I'm hovering on. 2) Click on that Element (it's a link). 3) Verify that opened URL is what expected.
Step 3 would be easy if opened URL was actually the same as the one obtained in step 1. However, the URL in my case gets redirected until it finally opens, thus my test case fails.
My current implementation: 1) With this method I get the URL:
public String getHrefFromElement(String selector) {
return driver.findElement(By.cssSelector(selector)).getAttribute("href");
}
2) I click with this method on the selector:
public void click(String selector) {
driver.findElement(By.cssSelector(selector)).click();
}
3) After clicking I'd get current URL and write basic assertion for comparing Href from Element obtain in #1 with current URL (it would fail).
public String getCurrentURL() {
return driver.getCurrentUrl();
}
Question: If clicked on URL gets redirected, could I somehow verify that URL was being opened before redirect? How could I get URL state from the very start before the redirect before page loads?