One of the first Google links gives : Selenium C Sharp – Retrieving Current URL of the Page
C# and Selenium.WebDriver: How to get the current URL
I'm using the Selenium.WebDriver to do some work in web pages and things are working OK. One of my new tasks are to click on something in the web page and it navigates to a to a new page which I will scrape. This also works.
EdgeOptions edgeOptions = new EdgeOptions();
edgeOptions.UseChromium = true;
edgeOptions.BinaryLocation = @"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe";
EdgeDriver edgeDriver = new EdgeDriver(edgeOptions);
edgeDriver.Navigate().GoToUrl(@"https://www.SomeDoman.com/");
Along with scraping the page, I need to get the current URL which has changed since using the above code to open the page. I can't see any property for this.
How can I get the page's current URL
1 additional answer
Sort by: Most helpful
-
Jack J Jun 24,611 Reputation points Microsoft Vendor
2021-08-16T03:06:47.627+00:00 @moondaddy , you could use EdgeDriver.Url Property to access the current URL.
I make a simple winform app and you could have a look.
private void button1_Click(object sender, EventArgs e) { textBox1.Text = driver.Url; } EdgeDriver driver = new EdgeDriver(); private void Form1_Load(object sender, EventArgs e) { driver.Navigate().GoToUrl("https://learn.microsoft.com/en-us/dotnet/csharp/"); textBox1.Text = driver.Url; }
Result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.