Identifying the elements using xpath and css in LeanFT in C#.Net

Below example illustrates how to use XPATH and CSS selectors to identify the web elements in LeanFT in C#.Net.

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using HP.LFT.SDK;
using HP.LFT.Verifications;
using System.Diagnostics;
using System.Threading;
using HP.LFT.SDK.Web;

namespace LeanFtTestProject1
{
    [TestClass]
    public class LeanFtTest : UnitTestClassBase<LeanFtTest>
    {
        [ClassInitialize]
        public static void ClassInitialize(TestContext context)
        {
            GlobalSetup(context);
        }

        [TestInitialize]
        public void TestInitialize()
        {

        }

        [TestMethod]
        public void TestMethod1()
        {
           IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

            // Navigate to www.softpost.org
            browser.Navigate("https://www.softpost.org/selenium-test-page/");

            // Find edit box using Xpath
            IEditField firstName = browser.Describe <IEditField>(new EditFieldDescription
            {
                XPath = "//input[@id='fn']"
                
            });

            firstName.SetValue("XPATH");

            // Find edit box using CSS
            firstName = browser.Describe<IEditField>(new EditFieldDescription
            {
                CSSSelector = "input[id='fn']"

            });

            firstName.SetValue("CSS");

            browser.Close();
        }

        [TestCleanup]
        public void TestCleanup()
        {
        }

        [ClassCleanup]
        public static void ClassCleanup()
        {
            GlobalTearDown();
        }
    }
}

You may also like...