Getting the URL of the current page using Selenium WebDriver

JavaSeleniumWebdriver

Java Problem Overview


I'm attempting to get the URL of the currently open page. I am using Selenium WebDriver and Java.

I am accessing the current URL via:

WebDriver driver = new WebDriver();
String url = driver.getCurrentUrl();

however, the URL does not appear to actually reflect where I currently am.

My current test case involves going to the NYT website and then clicking on the "Technology" link. However, url appears to always be http://www.nytimes.com/, regardless of the URL that is displayed in the address bar.

How do I actually access the value of the URL that's in the address bar so I can tell what page I'm actually on?

Java Solutions


Solution 1 - Java

Put sleep. It will work. I have tried. The reason is that the page wasn't loaded yet. Check this question to know how to wait for load - https://stackoverflow.com/questions/5868439/wait-for-page-load-in-selenium

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKarenView Question on Stackoverflow
Solution 1 - JavaAvihai MarchianoView Answer on Stackoverflow