Share this page

CSSSelector Property (WebElementDescription)
The path to the object in CSS format, for example, tr.BPTRow input.

C# Syntax

    public CSSDescription CSSSelector {get; set;}

Example

    // Suppose you want to verify that when entering a value in a search box, a suggestion box opens.
    // The only way to identify the suggestion box is via a CSS selector.

    // The example below shows how to:
    // - fire an event that triggers the opening of a suggestion box
    // - identify the suggestion box using a CSS selector

    [Test]
    public void Verify_SearchSuggestionsAreOpenUponUserInput()
    {
        // Launch the Chrome browser and navigate to the web site.
        var browser = BrowserFactory.Launch(BrowserType.Chrome);
        browser.Navigate("http://www.google.com");

        // Use Try/Catch to add a warning to the run report if the assert validation fails.
        try
        {
            // Enter the value "Some Text" in the search box.
            var search = browser.Describe<IEditField>(new EditFieldDescription
            {
                Name = "q"
            });
            search.SetValue("Some Text");

            // Simulate a single key down event to trigger the opening of the suggestion box.
            search.FireEvent(EventInfoFactory.CreateEventInfo("onkeydown"));

            // Wait until the suggestion box opens.
            var suggestions = browser.Describe<IWebElement>(new CSSDescription(".sbsb_a"));
            suggestions.WaitUntil(suggestionsBox => suggestionsBox.Exists() && suggestionsBox.IsVisible);

            // Verify that the suggestion box exists and is visible.
            Verify.IsTrue(suggestions.Exists(), "Verify Search Suggestions UserInput Control Exists", "Verify that the suggestion box exists.");
            Verify.IsTrue(suggestions.IsVisible, "Verify Search Suggestions UserInput Control Is Visible", "Verify that the suggestion box is visible.");
        }
        catch (Exception e)
        // Use a ReportEvent step to add details to the report if there is an error in the test.
        {
            Reporter.ReportEvent("Verify_SearchSuggestionsAreOpenUponUserInput", "Failed during validation", Status.Failed, e);
            throw;
        }
        finally
        {
            browser.Close();
        }
    }

Tips to improve your search results... OpenText™ Functional Testing for Developers .NET SDK Version: 25.2 OpenText™ Functional Testing for Developers SDK 25.2 All View Local Help Center View Online Help Center Version: