Skip to main content

Demo Project (Selenium Setup)



Setting up WebDriver
1.Create a new project from Console App
2.Install Selenium NuGet packages



3.Download the driver for particular browser.For Firefox browser we don’t need to install the driver.Here we installed Chrome driver using below link.It actually runs directly.
https://chromedriver.storage.googleapis.com/index.html?path=2.40/


4.Add OpenQA namespace under Selenium and we need to import namespace for browser also.


5.Now we write a small code which open up our browser and go to google.com.


6.Output of the code





7. Finding Elements
For finding elements we have to right click on the element we want and click on inspect option.



8.Then we will see that element must has an Id or class or we can also use Xpath to select the element.



9.Now we extends the previous code which will search for “Selenium”



10.Then it will select the image option and will click the first image of selenium.



11.Extended code


using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;

namespace SeleniumDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            IWebDriver driver = new ChromeDriver();
            driver.Url = "https://www.google.com/ncr";

            var searchbox = driver.FindElement(By.Id("lst-ib"));
            searchbox.SendKeys("Selenium");
            searchbox.SendKeys(Keys.Enter);

            var imageOption = driver.FindElement(By.ClassName("qs"));
            imageOption.Click();

            var image = driver.FindElement(By.Id("i48MSmX01sE18M:"));
            image.Click();

        }
    }
}


12.Output of the code


Comments

Popular posts from this blog

JIRA OverView

What is JIRA? JIRA is a project management tool used for issues and bugs tracking system for all types of testing.The JIRA dashboard consists of many useful functions and features which make handling of issues easy. The following points explain some interesting details of JIRA. • JIRA is an incident management tool. • JIRA is not an acronym, the name 'JIRA' comes from the Japanese word 'Gojira' • JIRA is developed by Australian Company Atlassian • JIRA is a platform independent tool; it can be used with any OS. • JIRA is multi-lingual tool − English, French, German, Japanese, Spanish, etc. • JIRA can be integrated with many other tools like GitHub, Team Foundation Software and many more. • JIRA is a commercial tool and available as a Trial version for a limited time. • To utilize JIRA services, a license is required. Features: JIRA is one the best product management tool which includes: Issue tracking & management: A software application that allows to...

Page Object Model && Page Factory

Page Object Model Design Pattern (POM): Page Object Model is a Design Pattern which has become popular in Selenium Test Automation. It is widely used design pattern in Selenium for enhancing test maintenance and reducing code duplication. In Selenium all we are doing is finding elements and filling values for those elements. For small script it’s easy to maintain . But with time test suite will grow. As we add more and more lines to our code, things become tough.The chief problem with script maintenance is that if 10 different scripts are using the same page element, with any change in that element, we need to change all 10 scripts. This is time consuming and error prone. A better approach to script maintenance is to create a separate class file which would find web elements, fill them or verify them. This class can be reused in all the scripts using that element. In future, if there is a change in the web element, we need to make the change in just 1 class file and not 1...

Screenshot in Selenium Webdriver (C#)

Selenium WebDriver provides the option to capture screenshots during a test execution. This is very important when we need to investigate different failures in test cases or unexpected window popup during test execution or in some cases to track the different stages of the run. Sometimes we need the screenshots to understand at the end of long running test execution on why the test case got failed.We can save the screenshots in a local folder of our computer. In Selenium Webdriver the screen shots are taken using Screenshot class. The ITakesScreenshot interface has method called GetScreenshot() which takes screenshot of the page on the screen. Here is the Code to take screenshot of a page.          #region screenshots public class ScreenShotClass { public static string Save (IWebDriver driver, string ScreenShotFileName) { var folderLocation = ( @"" );//Path of the folder to save the f...