WPF code sample

Change a toggle button state

This example locates a toggle button and changes the toggle button state.

@Test
public void testWpfToggleButton() throws GeneralLeanFtException {			
 // Identify the application that has the toggle button.
 Window appMainWindow = Desktop.describe(Window.class, new WindowDescription.Builder().objectName("MainWindow").fullType("window").windowTitleRegExp("MainWindow").build());
			
 // Identify the button that supports the WPF toggle mechanism.
 Button buttonWithToggleButtonSupport = appMainWindow.describe(Button.class, new ButtonDescription.Builder().text("Toggle Button").objectName("Button4").build());			
 ToggleButton toggleButton = buttonWithToggleButtonSupport.getToggleButton();
        			
 // Set the toggle button's state to checked.			
 toggleButton.set(CheckedState.CHECKED); 
			
 // Change the toggle button state.
 if (toggleButton.isChecked()) {			
  toggleButton.set(CheckedState.UNCHECKED);			
 } else {			
  toggleButton.set(CheckedState.CHECKED);			
 }			
}		

Back to top

See also: