HomeSelenium C#

Selenium C Sharp – Closing the Browser using Close()

Selenium C Sharp – Closing the Browser using Close()

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

In the previous article, I have practically demonstrated  refreshing the page using Selenium C# API Command – Refresh().

In this article, I am going to practically demonstrated closing the browser window using Selenium C# API command Close().

Let’s get started.

Selenium C Sharp – Closing the Browser using Close()

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, halt the program for 5 seconds and then close the Browser window.

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) Write the below code for halting the program for 5 seconds for demonstration purpose as shown below:

Selenium C# - Thread Sleep

4) Now write the Close() command as shown below:

driver.Close();

Selenium C# - driver Close

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

Observe that the Selenium C# Script will get executed and the following will happen in sequence:

  1. Application URL will open in Chrome Browser in Maximized mode
  2. Program will halt for 5 seconds
  3. Browser page will be closed

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