Open topic with navigation

XPathDescription Class
The description of a Web test object based on the object’s XPath.

C# Syntax

    public class XPathDescription : HP.LFT.SDK.PropertiesDescription, HP.LFT.SDK.IDescription

Example

    [Test]
    public void verify_CurrentDateIsPresented()
    {
        // Suppose you want to verify that the AUT's home page displays today's date, but the date label does not have identification properties, and the text is dynamic.
        // You can use the label's XPath to locate it and verify that the text represents the current date.

        // Open the Chrome browser.
        var browser = BrowserFactory.Launch(BrowserType.Chrome);

        // Use Try/Catch to add a warning to the run report if the assert validation fails.
        try
        {
            // Navigate to the New Tours website.
            browser.Navigate("http://newtours.demoaut.com/");

            // Locate the label using its XPath.
            var dateLabel = browser.Describe<IWebElement>(new XPathDescription("/html/body/div/table/tbody/tr/td[2]/table/tbody/tr[4]/td/table/tbody/tr/td[2]/table/tbody/tr[2]/td[3]/form/table/tbody/tr[1]/td/font/b"));

            // Convert the date into .NET object.
            var presentedDate = DateTime.Parse(dateLabel.InnerText);

            // Verify that today's date matches the date displayed.
            Assert.AreEqual(DateTime.Now.Date, presentedDate.Date);
        }
        catch (Exception e)
        // Use a ReportEvent step to add details to the results report if there is an error in the test.
        {
            Reporter.ReportEvent("verify_CurrentDateIsPresented", "Failed during validation", Status.Failed, e);
            throw;
        }
        finally
        {
            browser.Close();
        }
    }

Inheritance Hierarchy

System.Object
HP.LFT.SDK.PropertiesDescription
HP.LFT.SDK.Web.XPathDescription

Public Constructors

| Name | Description
--- | --- | ---
| XPathDescription Constructor | Overloaded. Initializes a new instance of the XPathDescription class.

Top
Public Methods

| Name | Description
--- | --- | ---
| Clone | Creates an exact copy of the test object. (Inherited from HP.LFT.SDK.PropertiesDescription )
| ToString | ToString override. The string representation of this XPathDescription object.

Top
Public Operators

Implicit Type Conversion | Implicit cast of the specified string to an XPathDescription.

Top