Share this page

# Web code samples (.NET SDK)

In this topic:

## Send keystrokes to the AUT

To send the Enter key, use the Keyboard class:

    Keyboard.PressKey(28);

To send the Enter key to a specific web control, you sometimes need to make sure it has the focus.

This can be done using one of the following:

- the click() method of the control:

      browser.Describe<IEditField>(newCSSDescription(@"input#newCommentInput")).Click(MouseButton.Left);

- the Mouse class

      var edit = browser.Describe<IEditField>(newCSSDescription(@"input#newCommentInput"));

      // Use Mouse class to click on the edit field
      var loc = edit.AbsoluteLocation;
      var p = newPoint(loc.X + 5, loc.Y + 5);

      Mouse.Click(p, MouseButton.Left);

Back to top

## Simple link click

The following example demonstrates a simple Click step on a web link.

    [Test]
    	public void TestLinkClick()
    	{

    	// Launch the Chrome browser.
    	IBrowser testBrowser = BrowserFactory.Launch(BrowserType.Chrome);

    	// Navigate to the AdventageDEMO web site
    	testBrowser.Navigate("http://advantageonlineshopping.com/#");

    	// Create a test object with a unique description for the 'Tablets' link.
    	var tabletLink = testBrowser.Describe<ILink>new LinkDescription {InnerText="Tablets"});

    	// Click the link.
    	tabletLink.Click(); }

Back to top

## Programmatic description vs. Application Model code

The Programmatic description example shows a set of steps with test objects created using programmatic descriptions.

The Application Model code example shows a similar set of steps using test objects from an application model.

Programmatic description example

This example uses a Verify command to verify the price of a product.

To see how to perform this verification with an application model, see the Application Model code example.

    [Test]
    public void ProgrammaticVsApplicationModel1()
    {
        // Launch the browser and navigate to the Advantage Online Shopping site, to the "Speakers" section.
        var browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
        browser.Navigate("https://www.advantageonlineshopping.com/#/category/Speakers/4");

        // Click the 'BOSE SOUNDLINK BLUETOOTH SPEAKER III' link.
        browser.Describe<ILink>(new LinkDescription
        {
            TagName = @"A",
            InnerText = @"Bose Soundlink Bluetooth Speaker III"
        }).Click();

        // Define the object that displays the price.
        var priceElem = browser.Describe<IWebElement>(new WebElementDescription
        {
            ClassName = @"roboto-thin screen768 ng-binding",
            InnerText = As.RegExp("$269.*"),
            TagName = @"H2"
        });
        // Verify that the price in the object is as expected.
        Verify.AreEqual("$269.99", priceElem.InnerText);
    }

Application Model code example

This example uses Verify on an object from an application model to perform the same type of check as in the Programmatic description example.

    [Test]
    public void ProgrammaticVsApplicationModel2()
    {
        // Launch the browser and navigate to the Advantage Online Shopping site, to the "Speakers" section.
        var browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
        browser.Navigate("https://www.advantageonlineshopping.com/#/category/Speakers/4");

        // Create an instance of the application model and provide the browser defined above as the parent object.
        DiscoverAppModel app = new DiscoverAppModel(browser);

        // Click the section for speakers.
        app.Speakers.Click();

        // Click the 'BOSE SOUNDLINK BLUETOOTH SPEAKER III' link.
        app.SpeakersPage.BoseSoundlinkBluetoothSpeaker.Click();

        // Verify that the price in the object is as expected.
        Verify.AreEqual("$269.99", app.BoseSoundlinkBluetoothSpeakerPage.Price);
    }

Back to top

## Navigate to a web site

The following example uses a Verify command to verify navigation to a web site.

    [Test]
     public void Verify_linkNavigatesSpeakersSite()
    {
        //Launch the Chrome browser.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

        try
        {
            //Navigate to the Advantage Online Shopping website.
            browser.Navigate("http://advantageonlineshopping.com/");

            // Click the "Speakers" link (in the top-left side of the page).
            browser.Describe<ILink>(new LinkDescription
            {
                TagName = @"DIV",
                InnerText = @"SPEAKERS Shop Now "
            }).Click();

            //Wait for the browser to complete the navigation.
            browser.Sync();

            //Verify that the correct page Web page opens.
            Verify.AreEqual("http://advantageonlineshopping.com/#/category/Speakers/4", browser.URL,
                            "Verify_linkNavigatesSpeakersSite", "Verify that the browser's URL is as expected.");
        }
        catch (Exception e)
        {
            Reporter.ReportEvent("Verify_linkNavigatesSpeakersSite", "Failed during validation", Status.Failed, e);
            throw;
        }
        finally
        {
            browser.Close();
        }
    }

Back to top

## Access Web objects in a tab opened by the AUT

OpenText Functional Testing for Developers recognizes browser windows and tabs that it opens (for example, via BrowserFactory.Launch).

However, if a browser is opened outside of the OpenText Functional Testing for Developers context, you need to use the Attach method to acquire the IBrowser Interface instance for the browser tab or window.

Attach a browser when:

- If you open a browser manually while setting up a scenario prior to running a test
- If a step in your test clicks a link that opens a new or replacement browser tab or window

The example below attaches a newly opened browser tab.

    [Test]
    public void Verify_AboutOpensCorrectly()
    {
        //Launch the Chrome browser.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

        // Use Try/Catch to add a warning to the run report if the Verify validation fails.
        try
        {
            //Navigate to the Advantage Online Shopping website.
            browser.Navigate("http://advantageonlineshopping.com/");

            //Click the "SPEAKERS" link.
            browser.Describe<ILink>(new LinkDescription
            {
                TagName = @"DIV",
                InnerText = @"SPEAKERS Shop Now "
            }).Click();

            //Attach the new (replacement) browser tab.
            IBrowser aboutTab = BrowserFactory.Attach(new BrowserDescription
            {
                Title = "Advantage Shopping"
            });

            //Create a description for the page title.var aboutTitle = aboutTab.Describe<IWebElement>(new WebElementDescription
            {
                Title = @"Advantage Shopping",
                Index = 0
            });

            // Validate that a page title exists.
            Verify.IsTrue(aboutTitle.Exists(), "Verify_AboutOpensCorrectly", "Validate that the title page exists.");
        }
        catch (Exception e)
        // Add a log message to the results report if there is an error in the test.
        {
             Reporter.ReportEvent("Verify_AboutOpensCorrectly", "Failed during validation", Status.Failed, e);
            throw;
        }
        finally
        {
            browser.Close();
        }
    }

Back to top

## Locate an object by its XPath

Suppose you want to click the login button, but the button does not have identification properties.

You can use the button's XPath to locate it and then click the button.

See an example below.

    [Test]
    public void Verify_IdentifyLoginButtonByXPath()
    {
        //Launch the Chrome browser.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

        // Use Try/Catch to add a warning to the run report if the Verify validation fails.
        try
        {
            //Navigate to the Advantage Online Shopping website.
            browser.Navigate("http://advantageonlineshopping.com/");

            //Click the "User Menu" link (on the left side of the page).
            var userMenulink = browser.Describe<ILink>(new XPathDescription("//A[@id=\"menuUserLink\"]"));
            userMenulink.Highlight();
            userMenulink.Click();

            // Enclosing the Verify method in a try-catch statement ensures the application does not throw
            // a runtime error if the Verify returns false. Verify that the log in fields are visible
            var userName = browser.Describe<IEditField>(new EditFieldDescription
            {
                Type = @"text",
                Name = @"userName"
            });
            var password = browser.Describe<IEditField>(new EditFieldDescription
            {
                Type = @"password",
                Name = @"password"
            });

    	Verify.IsTrue(userName.Exists(), "Verify_IdentifyLoginButtonByXPath",
                                            "Verify that user Name field is visible after identifying the login button after XPath.");
    	Verify.IsTrue(password.Exists(), "Verify_IdentifyLoginButtonByXPath",
                                            "Verify that password field is visible after identifying the login button after XPath.");
        }
        catch (Exception e)
        // Add a log message to the results report if there is an error in the test.
        {
            Reporter.ReportEvent("Verify_IdentifyLoginButtonByXPath", "Failed during validation", Status.Failed, e);
            throw;
        }
        finally
        {
            browser.Close();
        }
    }

Back to top

## Use Verify to validate a successful log in

This example validates the success of a log in operation by checking for the account name at the top of the screen.

    [Test]
    public void Verify_UserCanSuccessfullyLogIn()
    {
        // Navigate to the Advantage Online Shopping website.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);
        browser.Navigate("http://advantageonlineshopping.com/");

        try
        {
            // Open the menu to Navigate to the log in option.
            var userMenuLink = browser.Describe<ILink>(new LinkDescription
            {
                CSSSelector = @"a#menuUserLink",
                TagName = @"A"
            });
            userMenuLink.Click();

            // Log in to the web site.
            var userName = browser.Describe<IEditField>(new EditFieldDescription
            {
                Type = @"text",
                Name = @"userName"
            });
            var password = browser.Describe<IEditField>(new EditFieldDescription
            {
                Type = @"password",
                Name = @"password"
            });

            // Set the userName and password.
            userName.SetValue("MyName");
            password.SetValue("55940Fd62c96");

            // Click the SIGN IN button.
            browser.Describe<IButton>(new ButtonDescription
            {
                ButtonType = @"button",
                Name = @"SIGN IN",
                TagName = @"BUTTON"
            }).Click();

            //Verify that user Name appears in the top-right corner after logging in.
            Verify.IsTrue(userMenuLink.InnerText.Contains("MyName"), "Verify_UserCanSuccessfullyLogIn",
                                             "Verify that user Name appears in the top-right corner after logging in.");
        }
        catch (Exception e)
        {
            Reporter.ReportEvent("Verify_UserCanSuccessfullyLogIn", "Failed during test", Status.Failed, e);
            throw e;
        }
        finally
        {
            browser.Close();
        }
    }

Back to top

## Synchronize objects using WaitUntil

The following example shows how to verify that a suggestion box contains suggestions. It contains a WaitUntil step to give the objects in the application time to load fully before continuing to the next step.

The test navigates to the AUT, opens the suggestion box from the search box, waits until the suggestion box opens, and verifies that the suggestion box contains at least one suggestion.

     [Test]
    public void Verify_SearchSuggestionsArePresentedAndMoreThan0()
    {
    	// The following example shows how to verify that a suggestion box contains suggestions.
    	// It contains a WaitUntil step to give the objects in the application time to load fully
    	// before continuing to the next step.

    	// The test navigates to the AUT, opens the suggestion box from the search box,
    	// waits until the suggestion box opens, and verifies that the suggestion box
    	// contains at least one suggestion.

    	// 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 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"));

    		// Identify the suggestion box using a CSS selector and wait until the suggestion box opens.
    		var suggestions = browser.Describe<IWebElement>(new WebElementDescription
    		{
    			CSSSelector = @".sbsb_a",
    		});
    		suggestions.WaitUntil(suggestionsBox => suggestionsBox.Exists() && suggestionsBox.IsVisible);

    		var suggestionList = suggestions.FindChildren<IWebElement>(new WebElementDescription
    		{
    			TagName = "LI"
    		});

    		// Verify that the suggestion box exists and contains content.
    		Verify.IsTrue(suggestions.IsVisible, "Verify_SearchSuggestionsAreOpenUponUserInput", "Verify suggestion box exists.");
    		Verify.Greater(suggestionList.Length, 0, "Verify_SearchSuggestionsAreOpenUponUserInput", "Verify suggestion box contains content.");

    	}
    	catch (Exception e)
    	// Use a ReportEvent step to add details to the run report if there is an error in the test.
    	{
    		Reporter.ReportEvent("Verify_SearchSuggestionsAreOpenUponUserInput", "Failed during validation", HP.LFT.Report.Status.Failed, e);
    		browser.Close();
    		throw;
    	}

    }

Back to top

## Retrieve list items and print them

The following example shows how to retrieve values from a list and print them.

The test signs in to the AUT, adds some items to the shopping cart, and then prints the values to the console.

    [Test]
    public void Verify_retrieveShoppingCartValues()
    {
        // The test goes to the AUT, adds some items to the shopping cart, and then prints the values to the console.
        //Open the Chrome browser.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

        // Navigate to the Advantage Online Shopping website.
        browser.Navigate("https://www.advantageonlineshopping.com");

        // Navigate to the "Speakers" link (on the top-left side of the page).
        browser.Describe<ILink>(new LinkDescription
        {
            InnerText = @"SPEAKERS Shop Now ",
            TagName = @"DIV"
        }).Click();

        // Click the Bose Soundlink Bluetooth Speaker III item.
        var boseSoundlinkBluetoothSpeaker = browser.Describe<IWebElement>(new WebElementDescription
        {
            InnerText = @"SOLD OUT SHOP NOW Bose Soundlink Bluetooth Speaker III $269.99 ",
            TagName = @"LI"
        });
        boseSoundlinkBluetoothSpeaker.Click();

        // Identify the "ADD TO CART" button.
        var saveToCartButton = browser.Describe<IButton>(new ButtonDescription
        {
            ButtonType = @"submit",
            Name = @"ADD TO CART",
            TagName = @"BUTTON"
        });

        // Add the selected item to cart.
        saveToCartButton.Click();

        // Navigate back to speakers.
        var speakersLink = browser.Describe<ILink>(new LinkDescription
        {
            InnerText = @"SPEAKERS ",
            TagName = @"A"
        });
        speakersLink.Click();

        // Click the Bose SoundLink Wireless Speaker item.
        var boseSoundLinkWirelessSpeaker = browser.Describe<IWebElement>(new WebElementDescription
        {
            InnerText = @"SOLD OUT SHOP NOW Bose SoundLink Wireless Speaker $129.00 ",
            TagName = @"LI"
        });
        boseSoundLinkWirelessSpeaker.Click();

        // Add the selected item to cart.
        saveToCartButton.Click();

        // Go to the shopping cart.
        browser.Describe<ILink>(new LinkDescription
        {
            AccessibilityName = @"ShoppingCart",
            Role = @"link",
            TagName = @"A"
        }).Click();

        var shoppingCartTable = browser.Describe<ITable>(new TableDescription
        {
            Index = 1,
            Role = @"",
            TagName = @"TABLE"
        });

        // Identify the items in the shopping cart Table element.
        var wirelessSpeakerCartRow = shoppingCartTable.FindRowWithCellText("WIRELESS");
        var bluetoothSpeakerCartRow = shoppingCartTable.FindRowWithCellText("BLUETOOTH");

        // Print the shopping cart cells to the console.
        foreach (ITableCell cell in wirelessSpeakerCartRow.Cells)
        {
            Console.WriteLine("cellText: " + cell.Text + " ");
        }

        foreach (ITableCell cell in bluetoothSpeakerCartRow.Cells)
        {
            Console.WriteLine("cellText: " + cell.Text + " ");
        }

        // Close the browser.
        browser.Close();
    }

Back to top

## Retrieve and validate list values

The following example shows how to retrieve the values from a drop-down list and validate some values in the list.

The test navigates to the AUT, clicks the Contact Us button, and then retrieves and checks some items from the drop-down list of categories.

    [Test]
    public void Verify_RetrieveProductCategoriesFromProductsListBox()
    {
        // Open the Chrome browser.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);

        try
        {
            // Navigate to the Advantage Online Shopping website.
            browser.Navigate("https://www.advantageonlineshopping.com/");

            // Navigate to the "CONTACT US" link
            browser.Describe<ILink>(new LinkDescription
            {
                InnerText = @"CONTACT US",
                TagName = @"A"
            }).Click();

            // Indentify the product categories list box
            var categoryListBox = browser.Describe<IListBox>(new ListBoxDescription
            {
                Name = @"categoryListboxContactUs",
                TagName = @"SELECT"
            });

            // Get the list items to Verify.
            IListItem laptopListItem = categoryListBox.Items[1];
            IListItem headphonesListItem = categoryListBox.Items[2];

            // Verify that the list items correspond with the expected values.
            Verify.AreEqual(laptopListItem.Text, "Laptops", "Verify_RetrieveProductCategoriesFromProductsListBox", "Verify that the first category is \"Laptops\"");
            Verify.AreEqual(headphonesListItem.Text, "Headphones", "Verify_RetrieveProductCategoriesFromProductsListBox", "Verify that the second category is \"Headphones\"");
        }
        catch (Exception e)
        {
            Reporter.ReportEvent("Verify_RetrieveProductCategoriesFromProductsListBox", "Failed during test", Status.Failed, e);
            throw e;
        }
        finally
        {
            browser.Close();
        }
    }

Back to top

## Identify an edit box via a CSS selector

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 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);

    		// Use Assert to verify that the suggestion box exists.
    		Assert.IsTrue(suggestions.IsVisible);
    	}
    	catch (AssertionException e)
    	// Use a ReportEvent step to add details to the report if the validation fails.
    	{
    		Reporter.ReportEvent("Verify_SearchSuggestionsAreOpenUponUserInput", "Failed during validation", Status.Failed, e);
    		throw;
    	}
    	finally
    	{
    		browser.Close();
    	}
    }

Back to top

## Verify that a suggestion box contains content

The following example shows how to verify that a suggestion box contains suggestions.

It contains a WaitUntil step to give the objects in the application time to load fully before continuing to the next step.

The test navigates to the AUT, opens the suggestion box from the search box, waits until the suggestion box opens, and verifies that the suggestion box contains at least one suggestion.

    [Test]
    public void Verify_SearchSuggestionsArePresentedAndMoreThan0()
    {
    	// The following example shows how to verify that a suggestion box contains suggestions.
    	// It contains a WaitUntil step to give the objects in the application time to load fully
    	// before continuing to the next step.

    	// The test navigates to the AUT, opens the suggestion box from the search box,
    	// waits until the suggestion box opens, and verifies that the suggestion box
    	// contains at least one suggestion.

    	// 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 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"));

    		// Identify the suggestion box using a CSS selector and wait until the suggestion box opens.
    		var suggestions = browser.Describe<IWebElement>(new WebElementDescription
    		{
    			CSSSelector = @".sbsb_a",
    		});
    		suggestions.WaitUntil(suggestionsBox => suggestionsBox.Exists() && suggestionsBox.IsVisible);

    		var suggestionList = suggestions.FindChildren<IWebElement>(new WebElementDescription
    		{
    			TagName = "LI"
    		});

    		// Verify that the suggestion box exists and contains content.
    		Verify.IsTrue(suggestions.IsVisible, "Verify_SearchSuggestionsAreOpenUponUserInput", "Verify suggestion box exists.");
    		Verify.Greater(suggestionList.Length, 0, "Verify_SearchSuggestionsAreOpenUponUserInput", "Verify suggestion box contains content.");

    	}
    	catch (Exception e)
    	// Use a ReportEvent step to add details to the run report if there is an error in the test.
    	{
    		Reporter.ReportEvent("Verify_SearchSuggestionsAreOpenUponUserInput", "Failed during validation", HP.LFT.Report.Status.Failed, e);
    		browser.Close();
    		throw;
    	}

    }

Back to top

## Find an element by using regular expressions

This example navigates to the application homepage using the application's Browser controls, then finds an element using a regular expression.

    [Test]
    public void Verify_FindElementByRegex()
    {
        // Launch the Chrome browser and navigate to the Advantage Online Shopping website.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);
        browser.Navigate("https://www.advantageonlineshopping.com");

        // Find the "Speakers" category element by Regex.
        var speakersElement = browser.Describe<IWebElement>(new WebElementDescription
        {
            Id = new RegExpProperty("speakers.*"),
            ClassName = new RegExpProperty(".*category.*")
        });

        //Verifies that the element is found.
        Verify.IsTrue(speakersElement.Exists(), "verify_FindElementByRegex", "Verify that the \"Speakers\" category element is found.");
    }

Back to top

## Identify an object using Visual Relation Identifiers (VRI)

This example shows how to use a symbol near a control in order to identify the control instead of using the control's properties.

This is helpful for controls that are generic, but are marked by specific symbols.

    [Test]
    public void Verify_MenuHelpItemUsingVRI()
    {
        // In order to identify the help expand arrow in the top-right corner,
        // we use the question mark symbol that is next to the arrow.
        // Open the Chrome browser and Navigate to the Advantage Online Shopping website.
        IBrowser browser = BrowserFactory.Launch(BrowserType.Chrome);
        browser.Navigate("https://www.advantageonlineshopping.com/");
        try
        {
            // Define the the question mark element next to the help expand arrow.
            var menuHelpWebElement = browser.Describe<IWebElement>(new WebElementDescription
            {
                AccessibilityName = @"",
                Index = 5,
                InnerText = @"",
                TagName = @"svg"
            });

            // Define the help arrow object using the VRI.
            var downArrowImage = browser.Describe<IImage>(new ImageDescription
            {
                // Define the visual relation identifier for the arrow, adding the test object described above.
                Vri =
                {
                    new VisualRelation
                    {
                        HorizontalRelation = HorizontalVisualRelation.Right,
                        TestObject = menuHelpWebElement,
                        ProximityRelation = ProximityVisualRelation.ClosestOnXAxis
                    }
                }
            });

            // Verify that the icon is visible.
            Verify.IsTrue(downArrowImage.IsVisible, "Verify_MenuHelpItemUsingVRI", "Verify that the menu help icon is visible using VRI.");

        }
        catch (Exception e)
        {
            Reporter.ReportEvent("Verify_MenuHelpItemUsingVRI", "Failed during test", Status.Failed, e);
            throw e;
        }
        finally
        {
            browser.Close();
        }
    }

Back to top

## Inject JavaScript into your webpage

This example shows how to inject JavaScript code into your webpage.

In this case, we use the JavaScript SpellCheck property to determine whether spell check is enabled.

    [Test]
    public void VerifySpellCheckIsEnabledOnSuggestionBox()
    {

    	var browser = BrowserFactory.Launch(BrowserType.InternetExplorer);
    	browser.Navigate("http://www.google.com");

    	// Determine whether spell check is enabled using the JavaScript SpellCheck property.
    	var performSpellCheck =
    		browser.Page.RunJavaScript<bool>(@"document.querySelectorAll('.sbdd_b')[0].spellcheck");
    	Verify.IsTrue(performSpellCheck, "Verify that spell check is enabled");
    	browser.Close();
    }

Back to top

## Wait for a button to exist and be enabled

This example shows waiting for a button to exist and be enabled.

    [Test]
    public void SpecificWaitMethodsExample()
    {

    	// Navigate to the Advantage Online Shopping website.
    	var browser = BrowserFactory.Launch(BrowserType.Chrome);
    	browser.Navigate("http://www.advantageonlineshopping.com/#/");

    	// Click the TABLETS image link
    	var tabletsShopNowLink = browser.Describe<ILink>(new LinkDescription
    	{
    		InnerText = @"TABLETS Shop Now ",
    		TagName = @"DIV"
    	});
    	tabletsShopNowLink.Click();

    	var buyNowButton = browser.Describe<IButton>(new ButtonDescription
    	{
    		ButtonType = @"submit",
    		Name = @"BUY NOW",
    		TagName = @"BUTTON"
    	});
    	bool buyNowButtonExists = buyNowButton.WaitUntilExists();
    	if (!buyNowButtonExists)
    		throw new GeneralLeanFtException("The buy now button does not exist");

    	bool buyNowButtonEnabled = buyNowButton.WaitUntilEnabled();
    	if (!buyNowButtonEnabled)
    		throw new GeneralLeanFtException("The buy now button is not enabled");

    	bool buyNowButtonVisible = buyNowButton.WaitUntilVisible();
    	if (!buyNowButtonVisible)
    		throw new GeneralLeanFtException("The buy now button is not visible");
    }

Back to top

https://admhelp.microfocus.com Functional Testing for Developers 8942
Tips to improve your search results... OpenText™ Functional Testing for Developers Help Center OpenText™ Functional Testing for Developers Help 25.2 All View Local Help Center View Online Help Center Version: