list
search
No matching documents found.
logo

JMeter Query Syntax

The SwingComponentTreeSelector is a powerful CSS-like selector engine used in the Webswing JMeter Plugin to locate and interact with a specific Swing component in your application. It allows you to target a single UI element using a familiar, web-like syntax for precise test automation.

Important: The selector should be specific enough to match exactly one component. If multiple components match, the first one found will be used.

Basic Syntax

The selector follows a CSS-like pattern to find one specific component:

ComponentType[attribute="value"]:pseudo-selector

Components of a Selector

  1. Component Type - The Swing component class name (e.g., JButton, JTextField)
  2. Attributes - Properties of the component in square brackets
  3. Pseudo-selectors - Special selectors starting with : for additional filtering
  4. Combinators - Relationship operators between selectors

Component Types

Target a specific component by its class name:

  • JButton - A specific button
  • JTextField - A specific text input field
  • JLabel - A specific text label
  • JTable - A specific table (or table cell)
  • JList - A specific list
  • JPanel - A specific panel
  • JFrame - A specific window/frame
  • JMenuItem - A specific menu item
  • JCheckBox - A specific checkbox
  • JRadioButton - A specific radio button

Examples:

JButton[name="loginBtn"]           # The login button specifically
JTextField[name="username"]        # The username text field
JTable[name="dataTable"]          # The data table

Attributes

Components have various attributes you can filter by:

Common Attributes

Attribute Type Description Example
name String Component name [name="submitButton"]
value String Component value/text [value="Save"]
enabled Boolean Whether component is enabled [enabled="true"]
visible Boolean Whether component is visible [visible="true"]
width Number Component width in pixels [width="200"]
height Number Component height in pixels [height="30"]
screenx Number X coordinate on screen [screenx="100"]
screeny Number Y coordinate on screen [screeny="50"]
selected Boolean Whether component is selected [selected="true"]
columnHeader String Column header (for table cells) [columnheader="ID"]
rowNumber Number Row index (for table cells) [rownumber="0"]

Using coordinates (screenx, screeny) or dimensions (width, height) is not recommended unless absolutely necessary, as they may change with UI layout adjustments.

Attribute Operators

Operator Description Example
= Exact match [name="button1"]
!= Not equal [enabled!="false"]
*= Contains [name*="submit"]
^= Starts with [name^="btn"]
$= Ends with [name$="Button"]
> Greater than (numbers) [width>"100"]
< Less than (numbers) [height<"50"]
>= Greater than or equal [screenx>="0"]
<= Less than or equal [screeny<="100"]

Pseudo-selectors

Pseudo-selectors provide additional filtering capabilities:

Position-based Selectors

Pseudo-selector Description Example
:first-child First child component JButton:first-child
:last-child Last child component JButton:last-child
:nth-child(n) The nth child component JButton:nth-child(2)

Relationship Selectors

Pseudo-selector Description Example
:root Root components JFrame:root
:parent Parent components JButton:parent
:ancestors All ancestor components JButton:ancestors
:descendants All descendant components JPanel:descendants
:siblings All sibling components JButton:siblings
:next-sibling Next sibling component JLabel:next-sibling
:prev-sibling Previous sibling component JButton:prev-sibling

Combinators

Combinators define relationships between elements:

Combinator Description Example
(space) Descendant selector JPanel JButton
> Direct child selector JPanel > JButton
+ Adjacent sibling selector JLabel + JTextField
~ General sibling selector JButton ~ JTextField

Common Usage Examples

Basic Component Selection

# Find button with specific name
JButton[name="submitBtn"]

# Find text field with specific value
JTextField[value="Enter text here"]

Table Operations

# Find table cell in specific column
JTable[columnheader="Name"]

# Find table cell with specific value in ID column
JTable[columnheader="ID"][value="12345"]

# Find first row in table
JTable:nth-child(1)

Complex Selections

# Find enabled submit button in a form panel
JPanel[name="formPanel"] > JButton[name*="submit"]:enabled

# Find text field next to a label
JLabel[value="Username:"] + JTextField

# Find all buttons in a dialog that are visible
JDialog JButton:visible

Position-based Selections

# First button in the application
JButton:first-child

# Last text field in a panel
JPanel JTextField:last-child

# Third menu item
JMenuItem:nth-child(3)

State-based Selections

# Visible buttons only
JButton:visible

# Hidden panels
JPanel:hidden

JMeter Plugin Usage

In the Webswing JMeter Plugin, use these selectors in the Query field:

Click Action Example

  • Action Type: click
  • Query: JButton[name="saveButton"]:enabled
  • Description: Clicks the enabled save button

Type Action Example

  • Action Type: type
  • Query: JTextField[name="username"]
  • Input: testuser
  • Description: Types "testuser" into the username field

Check Value Example

  • Action Type: checkValue
  • Query: JLabel[name="status"]
  • Value: Connected
  • Description: Verifies the status label shows "Connected"

Table Interaction Example

  • Action Type: click
  • Query: JTable[columnheader="Actions"][value="Edit"]
  • Description: Clicks the "Edit" button in the Actions column

Best Practices

1. Use Specific Selectors

# Good - specific and unlikely to match multiple elements
JButton[name="loginButton"]

# Avoid - too generic, may match many buttons
JButton

2. Combine Attributes for Precision

# Good - combines type, state, and content
JButton[value="Submit"]:enabled

# Better - adds more specific context
JPanel[name="loginForm"] JButton[value="Submit"]:enabled

3. Use Structural Relationships

# Find input field after its label
JLabel[value="Email:"] + JTextField

# Find button inside specific dialog
JDialog[name="confirmDialog"] JButton[value="OK"]

Troubleshooting

Common Issues

  1. No Element Found

    • Check if component names/values are correct
    • Verify the component is visible and enabled
    • Use broader selectors first, then narrow down
  2. Multiple Elements Matched

    • Add more specific attributes
    • Use structural relationships (parent/child)
  3. Selector Not Working

    • Verify attribute names are correct (case-sensitive)
    • Check for typos in pseudo-selectors
    • Ensure proper quotation marks around values