Working with Widgets

Widgets are on screen components/interfaces such as the bank, inventory, game tabs, world map, etc. The SimpleBot API provides methods to interact with widgets in the game client.

Widgets are identified by a unique ID and a component ID. The ID is used to identify the exact widget, and the component ID is used to identify a specific element within the widget.

Table of Contents

Getting Widgets

Getting a Widget by ID

To find a widget by ID, use the widgets.getWidget() method with the widget ID and component ID. This returns a SimpleWidget object that represents the specified widget. Here's an example:

final SimpleWidget inventory = ctx.widgets.getWidget(548, 65);
if (inventory != null) {
    System.out.println("Found widget: " + inventory.getId());
} else {
    System.out.println("Widget ID 548 not found.");
}

Getting a Widget by WidgetInfo

To find a widget by WidgetInfo, use the widgets.getWidget() method with the WidgetInfo object. This returns a SimpleWidget object that represents the specified widget. The WidgetInfo enum contains predefined widget IDs for common widgets in the game client, such as the inventory, bank, etc. The WidgetInfo enum is located in the net.runelite.api.widgets package. Here's an example of how to find the inventory widget using WidgetInfo:

final SimpleWidget inventory = ctx.widgets.getWidget(WidgetInfo.FIXED_VIEWPORT_INVENTORY_TAB);
if (inventory != null) {
    System.out.println("Found widget: " + inventory.getId());
} else {
    System.out.println("WidgetInfo FIXED_VIEWPORT_INVENTORY_TAB not found.");
}

Finding a Widget and its ID

The best way to find a widget and its ID is to use the RuneLite Widget Inspector. The Widget Inspector is a tool that allows you to inspect the widgets in the game client and get their IDs and component IDs. You can access the Widget Inspector by opening the 'Developer Tools' tab on the RuneLite client and clicking on the 'Widget Inspector' button.

Note: The Widget Inspector is only available in the RuneLite client, and you need to have the developer tools plugin enabled. Widget Inspector

Interacting with Widgets

Once you have found a widget, you can interact with it in various ways. The SimpleBot API provides methods to interact with widgets, such as clicking on them, getting their text, etc.

Interacting with a Widget using click(int option)

To interact with a widget using the click() method, you can specify the action name or action index. The click() method simulates a left-click on the specified widget. The option parameter is the index of the action to perform on the widget. The index starts from 0 for the first action and increments by 1 for each subsequent action.

Note: that not all widgets have multiple actions, so using click(0) is usually sufficient to interact with a widget.

Here's an example of how to interact with a widget using the click() method:

final SimpleWidget inventory = ctx.widgets.getWidget(548, 65);
if (inventory != null) {
    inventory.click(0);
} else {
    System.out.println("Widget ID 548 not found.");
}

Getting the Text of a Widget

To get the text of a widget, use the getText() method. This returns the text displayed on the widget. Here's an example:

final SimpleWidget chatbox = ctx.widgets.getWidget(162, 37);
if (chatbox != null) {
    System.out.println("Chatbox text: " + chatbox.getText());
} else {
    System.out.println("Widget ID 162 not found.");
}

Validating Widgets

The API offers the isHidden() and visibleOnScreen() methods to check if a widget is hidden or visible on the screen. The isHidden() method returns true if the widget is hidden, and false if it is visible. The visibleOnScreen() method returns true if the widget is visible on the screen, and false if it is not visible.

Typically only using isHidden() is sufficient to check if a widget is visible or not. However if a widget could be off screen e.g. a widget that has a scroll bar, then you would want to use visibleOnScreen() to check if the widget is visible on the screen.

Here's an example of how to validate a widget using the isHidden() method:

final SimpleWidget chatbox = ctx.widgets.getWidget(162, 37);
if (chatbox != null) {
    if (!chatbox.isHidden()) {
        System.out.println("Chatbox is visible.");
    } else {
        System.out.println("Chatbox is hidden.");
    }
} else {
    System.out.println("Widget ID 162 not found.");
}

Here's an example of how to validate a widget using the visibleOnScreen() method:

final SimpleWidget chatbox = ctx.widgets.getWidget(162, 37);
if (chatbox != null) {
    if (chatbox.visibleOnScreen()) {
        System.out.println("Chatbox is visible on screen.");
    } else {
        System.out.println("Chatbox is not visible on screen.");
    }
} else {
    System.out.println("Widget ID 162 not found.");
}
Last Updated:
Contributors: the-reminisce