- Our Selenium tutorials are designed specifically for beginners. We will start with the basics of Selenium and then as the tutorial progresses, we will move to the more advanced stuff. Selenium Introduction - Introduction to Selenium, its different components, advantages and limitations. Selenium WebDriver Setup - Java, Eclipse and Selenium.
- This Selenium WebDriver tutorial (Selenium WebDriver Blog: talks about the drawbacks of Selenium RC and what was the need for Selenium WebDriver. It goes into the details of.
- Selenium Tutorials for Beginners, WebDriver, Interview Questions, C#, Locators, Commands, Mobile, Applications, IDE.
- Selenium Tutorial For Beginners Learn Webdriver In 7 Days
- Learn Selenium Online For Free
- Selenium Webdriver Java Tutorial For Beginners Pdf
In this Selenium tutorial, you will also get to learn the different suites of Selenium and what are the features and shortcomings of Selenium as an automation testing tool. Our Selenium tutorial is designed for beginners and professionals. Selenium is one of the most widely used open source Web UI (User Interface) automation testing suite. Our Selenium tutorial includes all topics of Selenium such as Features, Selenium vs QTP, Selenium Tool Suits, Selenium IDE, Selenium IDE Locating Strategies, Selenium WebDriver.
Selenium Overview:
Selenium is an open-source, web Automation Testing tool that supports multiple browsers and multiple operating systems. It allows testers to use multiple programming languages such as Java, C#, Python, .Net, Ruby, PHP, and Perl for coding automated tests.
C # Overview:
C# is an object-oriented programming language derived from C++ and Java. C# allows developers to build applications using Visual Studio on .Net platform. The following are the key features of C#.
- It is an Object-Oriented programming language
- It supports the development of console, windows and web-based applications
- It provides features such as Encapsulation, Inheritance, and Polymorphism.
Basic Syntax of C #:
A program in C # need to contain the following sections
- Namespace declaration
- Classes
- Class Attributes and Methods
- Main method
- Program statements
Example-
Below is a sample C# program to print the text 'Guru99' on the system console.
Explanation:
- A namespace in C# is a collection of multiple classes. Each namespace must be declared using the keyword 'using'.
- The first statement of the code includes the namespace 'System' into our program. System namespace defines the fundamental classes and events used in C#. The namespace to be used depends on the program requirement.
- The second statement is declaring a namespace 'FirstProgram' for the class 'DemoPrint.' A C# file can contain multiple classes within the same namespace.
- The third statement includes the class declaration. A class may contain multiple attributes and multiple methods.
- The fourth statement includes a declaration of the Main method. The main method is the entry point of execution for each class.
- The last statement is the C# syntax used for printing a statement to console. WriteLine is a method of the class 'Console.
Set Up Visual Studio with Selenium WebDriver:
Visual Studio is an Integrated Development Environment (IDE) that is used by developers to build applications across multiple platforms such as Windows, Android, iOS and Cloud-based applications.
Step 1) Navigate to the URL https://www.visualstudio.com/downloads/ and Click on the 'Free download' button displayed on Visual Studio Community 2017 tab
Step 2) Open the exe downloaded. Click on 'Yes' if asked for Admin Rights.
Step 3) The below popup will appear. Click on 'Continue' button.
Files will be downloaded as shown in the popup below.
Step 4) In the next screen,
Select the checkboxes for
- Universal Windows Platform development
- Net desktop development
Click on 'Install.'
Wait for installation of each component to complete. Files are 16GB in size and will take time.
Step 5) The below pop up will be displayed. Click on 'Restart' button.
Step 6) Once the machine is restarted, search for 'Visual Studio 2017' on the start menu and click on the search result. The following popup will appear. Click on 'Not now, maybe later' link if you do not have an existing account.
Step 7) In the next screen,
- Select color theme of your liking
- Click the button 'Start Visual Studio'
Step 8) Visual Studio 'Get Started' screen will appear.
Create a new project in Visual Studio:
Step 1) In the File Menu, Click New > Project
Step 2) In the next screen,
- Select the option 'Visual C#'
- Click on Console App (.Net Framework)
- Enter name as 'Guru99'
- Click OK
Step 3) The below screen will be displayed once the project is successfully created.
Set up Visual Studio with Selenium WebDriver:
Step 1) Navigate to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution
Step 2) In the next screen
- Search for Selenium on the resultant screen
- Select the first search result
- Check the project checkbox
- Click on 'Install'
Step 3) Click on 'OK' button in the pop-up screen
Step 4) The below message will be displayed once the package is successfully installed.
NUnit Framework: Overview
NUnit is the Unit Testing framework supported by Visual Studio and Selenium WebDriver. NUnit is the most widely used Unit Testing framework for .Net applications. NUnit presents the test results in a readable format and allows a tester to debug the automated tests.
We need to install NUnit Framework and NUnit Test Adapter onto Visual Studio inorder to use it.
Steps to install NUnit Framework:
1. Navigate to Tools -> NuGet Package Manager -> Manage NuGet Packages for Solution
Step 2) In the next window https://educationrenew403.weebly.com/blog/toad-license-key-location.
- Search for NUnit
- Select the search result
- Select Project
- Click Install
Step 3) The below popup will appear. Click on 'Ok' button.
Step 4) The below message will appear once the installation is complete.
Steps to download NUnit Test Adapter
Please note that the below steps work only for 32-bit machines. For 64-bit machines, you need to download the 'NUnit3 Test Adapter' by following the same process as mentioned below.
Step 1) Navigate to Tools ->NuGet Package Manager -> Manage NuGet Packages for Solution. In that screen,
- Search NUnitTestAdapter
- Click Search Result
- Select Project
- Click Install
Step 2) Click OK on the confirmation pop-up. Once install is done you will see the following message-
Selenium and NUnit framework:
Integration of selenium with NUnit framework allows a tester to differentiate between various test classes. NUnit also allows testers to use annotations such as SetUp, Test, and TearDown to perform actions before and after running the test.
NUnit framework can be integrated with Selenium by creating a NUnit test class and running the test class using NUnit framework.
The below are the steps needed to create and run a test class using NUnit framework.
Steps to create a NUnit Test class in Selenium:
Step 1) In the Solution Explorer, Right click on project > Add > Class
Step 2) Class creation window will appear.
- Provide a name to the class
- Click on Add button
Step 3) The below screen will appear.
Step 4) Add the following code to the created class. Please note that you need to specify the location of 'chromdriver.exe' file during chrome driver initialization.
Step 4) Click on 'Build' -> 'Build Solution'
NOTE: You may get an error like 'Does not contain a static 'main' method suitable for an entry point' when you build
To resolve this Got to Project > Properties and change Output Type to 'Class Library.' The default is 'Console Application.'
Step 5) Once the build is successful, we need to open the Test Explorer window. Click on Test -> Windows -> Test Explorer
Step 6) Test Explorer window opens with the list of available tests. Right-click on Test Explorer and select Run Selected Tests
Step 7) Selenium must open the browser with specified URL and close the browser. Test case status will be changed to 'Pass' on the Test Explorer window.
Selenium WebDriver Commands in C#:
C# uses the interface 'IWebDriver' for browser interactions. The following are the category of commands available in C#.
- Browser commands
- Web Element commands
- Dropdown commands
Let's study them one by one
Browser commands:
The following are the list of browser commands available in C#.Command Name | Description | Syntax |
Url Command | This command is used to open a specified URL in the browser. | |
Title Command | This command is used to retrieve the page title of the web page that is currently open | |
PageSource Command | This command is used to retrieve the source code of web page that is currently open. | |
Close Command | This command is used to close the recently opened browser instance. | |
Quit Command | This command is used to close all open browser instances | |
Back Command | This command is used to navigate to the previous page of browser history. | |
Forward Command | This command is used to navigate to the next page of browser history. | |
Refresh Command | This command is used to perform browser refresh. |
Webelement Commands:
A Webelement represents all the elements on a web page. They are represented by HTML tags. Each of the buttons, textboxes, links, images, tables, and frames fall under Webelements. Operations on web elements can be triggered using the IWebelement interface. To interact with a Webelement, we need to find the element on the webpage and then perform operations on it. Tools like Firebug and Firepath can be used to identify the Xpath of Webelement.
The following are the list of Webelement commands available in C#. Command Name | Description | Syntax |
Click command | This command is used to click on a Webelement. For the element to be clickable, the element must be visible on the webpage. This command is used for checkbox and radio button operations as well. | |
Clear command | This command is specifically used for clearing the existing contents of textboxes. | |
SendKeys command | This command is used to input a value onto text boxes. The value to be entered must be passed as a parameter to | |
Displayed command | This command is used to identify if a specific element is displayed on the webpage. This command returns a Boolean value; true or false depending on the visibility of web element. | |
Enabled command | This command is used to identify if a particular web element is enabled on the web page. This command returns a Boolean value; true or false as a result. | |
Selected command | This command is used to identify if a particular web element is selected. This command is used for checkboxes,radio buttons, and select operations. | |
Submit command: | This command is similar to click command, The difference lies in whether the HTML form has a button with the type Submit. While the click command clicks on any button, submit command clicks on the only the buttons with type submit. | |
Text command | This command returns the innertext of a Webelement. This command returns a string value as a result. | |
TagName command | Dark pc games. This command returns the HTML tag of a web element. It returns a string value as the result. | |
GetCSSValue Command: | This method is used to return the color of a web element on the form of a rgba string (Red,Green,Blue, and Alpha). | Output- If the color of element is red, output would be rgba(255,0,0,1) |
Dropdown Commands:
Dropdown operations in C# can be achieved using the SelectElement class.
The following are the various dropdown operations available in C#. Command Name | Description | Syntax |
SelectByText Command | This command selects an option of a dropdown based on the text of the option. | |
SelectByIndex Command | This command is used to select an option based on its index. Index of dropdown starts at 0. | |
SelectByValue Command | This command is used to select an option based on its option value. | |
Options Command | This command is used to retrieve the list of options displayed in a dropdown. | The above code prints all the options onto console within a dropdown. |
IsMultiple command | This command is used to identify if a dropdown is a multi select dropdown; A multi select dropdown enables user to select more than one option in a dropdown at a time. This command returns a Boolean value. | |
DeSelectAll command | This command is used in multi select dropdowns. It clears the options that have already been selected. | |
DeSelectByIndex command | This command deselects an already selected value using its index. | |
DeSelectByValue command | This command deselects an already selected value using its value. | |
DeSelectByText command | This command deselects an already selected value using its text. |
Code Samples
Example 1: Click on a link using XPATH Locator:
Test Scenario:
- Navigate to Demo Guru99 web page - http://demo.guru99.com/test/guru99home/
- Maximize the window
- Click on the 'Testing' menu
- Close the browser
Example 2: Entering data into TextBox and Click on a button using XPATH locator:
Test Scenario:
- Navigate to Guru 99 demo page - http://demo.guru99.com/test/guru99home/
- Enter data into email text box
- Click on sign up button
Example 3: Entering data into TextBox and Click on a button using CSS locator:
Test Scenario:
- Navigate to Guru 99 demo page - http://demo.guru99.com/test/guru99home/
- Enter data into email text box
- Click on sign up button
Example 4: Select a value in the dropdown:
Test Scenario:
- Navigate to Guru 99 demo page - http://demo.guru99.com/test/guru99home/
- Click on SAP link
- Enter data onto name and email text boxes
- Select a value from the Course dropdown
- Close the browser
Summary:
- In order to use Selenium with C#, you need to install Visual Studio.
- NUnit is the Unit Testing framework supported by Visual Studio and Selenium WebDriver
- We need to install NUnit Framework and NUnit Test Adapter onto Visual Studio inorder to use it.
- NUnit framework can be integrated with Selenium by creating a NUnit test class and running the test class using NUnit framework.
- NUnit also allows testers to use annotations such as SetUp, Test, and TearDown to perform actions before and after running the test.
- Selenium WebDriver Commands can be categorized into Browser commands, Webelement Commands and Dropdown Commands.
This article is contributed by Sneha Gudapati
Training Summary
Selenium is a popular open-source web-based automation tool. This online course is a step by step guide to learn Selenium Concepts. It is recommended you refer the tutorials sequentially, one after the other.What should I know?
This free tutorial is designed for beginners with little or no automation experience. If you are new to testing first take the basic Software Testing class.
Want Selenium Lessons in your Inbox? Join our Email Course
Syllabus
First LookTutorial | What is Selenium? Introduction to Selenium Automation Testing |
Tutorial | What is Selenium WebDriver? Difference with RC |
It will be beneficial if you revisit Java, before reading tutorials on Webdriver
Tutorial | How to Download & Install Selenium WebDriver |
Tutorial | First Selenium Webdriver Script: JAVA Code Example |
Tutorial | Locators in Selenium IDE: CSS Selector, DOM, XPath, Link Text, ID |
Tutorial | Find Element and FindElements in Selenium WebDriver |
Tutorial | Selenium Form WebElement: TextBox, Submit Button, sendkeys(), click() |
Tutorial | How to Select CheckBox and Radio Button in Selenium WebDriver |
Tutorial | How to Click on Image in Selenium Webdriver |
Tutorial | How to Select Value from DropDown using Selenium Webdriver |
Tutorial | Locate Elements by Link Text & Partial Link Text in Selenium Webdriver |
Tutorial | Mouse Click & Keyboard Event: Action Class in Selenium Webdriver |
Tutorial | How to Upload & Download a File using Selenium Webdriver |
Tutorial | XPath in Selenium WebDriver: Complete Tutorial |
Tutorial | Alert & Popup Window Handling in Selenium WebDriver |
Tutorial | How to Handle Web Table in Selenium WebDriver |
Tutorial | Handling Dynamic Web Tables Using Selenium WebDriver |
Tutorial | Desired Capabilities in Selenium WebDriver |
Tutorial | How to Verify Tooltip using Selenium WebDriver |
Tutorial | How to Find All/Broken links using Selenium Webdriver |
Tutorial | Gecko (Marionette) Driver Selenium: Download, Install, Use with Firefox |
Selenium Tutorial For Beginners Learn Webdriver In 7 Days
TestNGTutorial | How to Download & Install TestNG in Eclipse for Selenium WebDriver |
Tutorial | TestNG Tutorial: Annotations, Framework, Examples in Selenium |
Tutorial | TestNG Groups: Include, Exclude with Example - Selenium Tutorial |
Tutorial | TestNG @Test Priority in Selenium |
Tutorial | Parallel Execution in Selenium: Session Handling & TestNG Dependency |
Tutorial | TestNG: How to Run Multiple Test Suites in Selenium |
Tutorial | TestNG Listeners in Selenium: ITestListener & ITestResult Example |
Tutorial | How to Execute Failed Test Cases in TestNG: Selenium WebDriver |
Tutorial | TestNG Report Generation in Selenium WebDriver |
Tutorial | Customize, PDF & Email TestNG Reports in Selenium WebDriver |
Tutorial | Page Object Model (POM) & Page Factory: Selenium WebDriver Tutorial |
Tutorial | Dataprovider & TestNG XML: Parameterization in Selenium(Example) |
Tutorial | Read & Write Data from Excel File in Selenium Webdriver: POI & JXL |
Tutorial | How to Select Date from DatePicker/Calendar in Selenium Webdriver |
Learn Selenium Online For Free
Advance Webdriver Stuff!Tutorial | Selenium Grid Tutorial: Hub & Node (with Example) |
Tutorial | Maven & Jenkins Integration with Selenium: Complete Tutorial |
Tutorial | Selenium Automation Framework: Data Driven, Keyword Driven & Hybrid |
Tutorial | Database Testing using Selenium: Step by Step Guide |
Tutorial | Handling iFrames in Selenium Webdriver: switchTo() |
Tutorial | Cross Browser Testing using Selenium WebDriver |
Tutorial | How to Take Screenshot in Selenium WebDriver |
Tutorial | Log4j with Selenium Tutorial: Download, Install, Use & Example |
Tutorial | Selenium Headless Browser Testing: HTMLUnitDriver & PhantomJS |
Tutorial | Robot Class in Selenium Webdriver |
Tutorial | How to use AutoIT with Selenium Webdriver: File Upload Example |
Tutorial | How to Handle SSL Certificate in Selenium WebDriver |
Tutorial | How to Handle AJAX Call in Selenium Webdriver |
Tutorial | JavaScriptExecutor in Selenium WebDriver with Example |
Tutorial | Selenium Webdriver using Python: Tutorial with Example |
Tutorial | How to use IntelliJ IDEA & Selenium Webdriver |
Tutorial | Flash Testing with Selenium WebDriver |
Tutorial | Apache ANT with Selenium: Complete Tutorial |
Tutorial | How to Generate XSLT Report in Selenium Webdriver |
Tutorial | Github Integration with Selenium: Complete Tutorial |
Tutorial | Cookies Handling in Selenium WebDriver |
Tutorial | Using SoapUI with Selenium for Web Service Testing |
Tutorial | How to Create Firefox Profile in Selenium WebDriver |
Tutorial | Selenium with Cucumber (BDD Framework): Tutorial with Example |
Tutorial | How to Drag and Drop in Selenium WebDriver (EXAMPLE) |
Tutorial | Selenium C# Webdriver Tutorial: NUnit Example |
Tutorial | Creating Object Repository in Selenium WebDriver: XML & Properties file |
Tutorial | How to Scroll Down or UP a Page in Selenium Webdriver |
Tutorial | Sikuli Tutorial: How to use Sikuli with Selenium (EXAMPLE) |
Tutorial | XPath Contains, Sibling, Ancestor Functions in Selenium WebDriver |
Tutorial | Implicit, Explicit, & Fluent Wait in Selenium WebDriver |
Tutorial | Double click and Right Click in Selenium with Examples |
Tutorial | Selenium Proxy Authentication using Webdriver with EXAMPLE |
Tutorial | How to Download & Install Selenium IDE for Firefox |
Tutorial | Selenium IDE Tutorial for Beginners |
Tutorial | How to use Selenium IDE with Scripts & Commands (Assert, Verify) |
Tutorial | Verify Element Present, waitFor, andWait in Selenium IDE |
Tutorial | Store Variables, Echo, Alert, PopUp handling in Selenium IDE |
Tutorial | Selenium Core Extensions (User-Extensions.js) |
Tutorial | Breakpoint & Start Point in Selenium IDE |
Tutorial | Maximize Browser in Selenium |
Tutorial | Chrome Options & Desiredcapabilities: AdBlocker, Incognito, Headless |
Tutorial | Refresh Page using Selenium Webdriver |
Tutorial | Top 100 Selenium Interview Questions & Answers |
Tutorial | Selenium vs HP UFT (QTP): What's the Difference? |
Tutorial | Top 15 Selenium Alternatives |
Tutorial | Selenium Tutorial PDF |
Selenium Webdriver Java Tutorial For Beginners Pdf
Join | Live Selenium Project: Banking Domain |
Join | Live Ecommerce Project: Selenium Automation |