Share this page

# SAPUI5 code samples (.NET SDK)

In this topic:

## Select an item in a ListBox

This example shows how to locate and select an item in a list box using a property-based description.

     [Test]
    public void Verify_ListBoxSelectListItemByIndex()
    {
    	try
    	{
    		// Navigate to the AUT site.
    		_browser.Navigate("https://sapui5.netweaver.ondemand.com/sdk/#test-resources/sap/ui/commons/ListBox.html");

    		// Identify the list box.
    		var list = _browser.Describe<UI5.IListBox>(new UI5.ListBoxDescription
    		{
    			Id = @"lb3",
    			TagName = @"DIV"
    		});

    		// Select the first item by index.
    		list.Select(1);

    		// Check that only one item in the list box is selected.
    		Verify.AreEqual(1, list.SelectedItems.Count, "Verify_ListBoxSelectListItemByIndex", "Verify that only one item in the list box is selected.");
    	}
    	catch (Exception e)
    	{
    		Reporter.ReportEvent("Verify_ListBoxSelectListItemByIndex", "Failed during validation", Status.Failed, e);
    		throw;
    	}
    	finally
    	{
    		_browser.Close();
    	}
    }

Back to top

## Delete an item in a ListBox

This example shows how to locate and select an item in a list box using a property-based description

    [Test]

    public void Verify_ListBoxFunctionalityForSubType()
    {
    	try
    	{
    		// Navigate to the AUT site.
    		_browser.Navigate("https://sapui5.hana.ondemand.com/sdk/test-resources/sap/m/List.html");

    		// Select the ListBox.
    		_browser.Describe<UI5.IListBox>(new UI5.ListBoxDescription
    		{
    			TagName = @"DIV",
    			Name = @"List Overview"
    		}).Select(@"Standard List Thumb");

    		/* Click the Delete button. The delete button adds a button next to each item in the list box,
    		         * enabling you to select single items in the list box to delete. */
    		_browser.Describe<UI5.IButton>(new UI5.ButtonDescription
    		{
    			TagName = @"button",
    			ButtonType = @"submit",
    			Name = @"Delete"
    		}).Click();

    		// Identify the list box.
    		var listBox = _browser.Describe<UI5.IListBox>(new UI5.ListBoxDescription
    		{
    			TagName = @"DIV",
    			Name = @"Travel [List-Mode: Delete]"
    		});

    		// Delete the item from the ListBox.
    		listBox.Mobile.Delete(@"Work Accidents");

    	}
    	catch (AssertionException e)
    	{
    		Reporter.ReportEvent("Verify_ListBoxFunctionalityForSubType", "Failed during validation", Status.Failed, e);
    		throw;
    	}
    	finally
    	{
    		_browser.Close();
    	}
    }

Back to top

Tips to improve your search results... UFT Developer .NET SDK Reference Version 15.0-15.0.2 UFT Developer SDK Reference All View Local Help Center View Online Help Center back Go back in browser history forward Go forward in browser history Remove search highlights next topic Go to next topic previous topic Go to previous topic Print the current topic Version: