HomeSelenium C#

Selenium C Sharp – Retrieving Current URL of the Page

Selenium C Sharp – Retrieving Current URL of the Page

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

In the previous article, I have practically demonstrated retrieving the Page Title using Selenium C#.

In this article, I am going to practically demonstrated retrieving the Current Page URL using Selenium C# API command Url.

Let’s get started.

Selenium C Sharp – Retrieving the Current Page URL

In this article, I am going to practically demonstrate by providing the task first followed by solution.

Task: Open the http://omayo.blogspot.com URL in Chrome browser and retrieve the Current Page URL of the page.

Selenium C# - Retrieving this URL

Solution: Lets follow the below steps:

1) Launch Visual Studio and select an existing project which is already configured with Selenium and WebDriverManager as shown below:

Navigate URL - Launch Project

2) Write the below code explained in the previous posts for navigating to the http://omayo.blogspot.com URL in chrome browser in maximized mode as shown below:

Selenium C# - Basic

3) Now use the driver.Url to retrieve the title of the page  and hover the mouse to see the return type of Url command as shown below:

Selenium C# - Return type

4) Observe that the return type of Url is String, hence create a variable for String Class and assign the value retrieved by Url to the variable as shown below:

String url = driver.Url;

Screenshot:

Selenium C# - String url

5) Print the above retrieved and stored title in the variable as shown below:

Selenium C# - print url

6) Save and click on ‘Start’ button to execute the above code.

Observe that the Selenium C# Script will get executed and the Current URL of the page will be retrieved and printed as shown below:

Selenium C# - URL Printed

Here concludes this article.

In the next article, I will choose another Selenium command for performing different operation on the web page.

Next Steps:

  • > To learn more about Selenium C#, continue to the next post (Click on Next Post Link Below)
  • > Check complete Selenium C# Tutorial Contents here (Click here)

Please leave your questions/comments/feedback below.

Happy Learning ?

About Me > Naveen Repala

Connect to me on Linked In (Click here)

On a mission to contribute to the Software Testing Community in all possible ways.

<<Previous Post                            << Complete Tutorial>>                              Next Post>>

Comments (0)

Leave a Reply

Your email address will not be published. Required fields are marked *

For FREE Testing Tutorials & Videos

X
Open chat
Contact Us on Whatsapp