Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.
Locate the tree node that owns the expand control, click its semantic button (or the node if that is what the widget makes interactive), then wait for the expanded state or child group. Do not assume that clicking an SVG or receiving a successful click command means the branch opened. The reliable pattern is a stable, scoped locator plus an explicit wait for a visible postcondition.
Identify the control before writing a locator
Inspect the rendered DOM for the tree and the branch you need to open. A tree view commonly represents its hierarchy with tree, treeitem, and group roles. A parent item may expose aria-expanded="false" while closed and aria-expanded="true" while open; a leaf normally omits aria-expanded. Some widgets instead put the state on a row or cell in a treegrid, and some use a nested button or disclosure control for the actual click target.
Prefer a unique ID when one exists. Otherwise choose a stable attribute such as data-testid, a role and state combination, or a concise CSS selector. Selenium supports XPath too, but long positional paths such as /html/body/div[2]/... are fragile: adding a wrapper or changing layout can invalidate them.
Make the locator specific to both the intended tree and the visible branch label. Selecting the first closed treeitem or first arrow in the document can open the wrong branch when a page contains multiple trees or nested parents.
#1 Best Overall
- Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
- Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
- Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
- Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
- Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
Python: click an ARIA tree node and wait for expansion
This example uses Selenium’s Python bindings. Replace the tree container and label with selectors observed on the page. It scopes the lookup to the named item, prefers a nested button when present, waits until the target is interactable, and verifies the state change.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver, 10)
# Replace these selectors and the label with the target page's markup.
tree = wait.until(EC.presence_of_element_located(
(By.CSS_SELECTOR, "[role='tree']")
))
parent = tree.find_element(
By.XPATH,
".//*[@role='treeitem' and @aria-expanded='false']"
"[.//*[normalize-space()='Reports']]"
)
# Many widgets make a nested button, not the entire row, the disclosure target.
buttons = parent.find_elements(By.CSS_SELECTOR, "button, [role='button']")
control = buttons[0] if buttons else parent
wait.until(lambda d: control.is_displayed() and control.is_enabled())
control.click()
# Verify the UI state, rather than assuming the click finished the interaction.
wait.until(lambda d: parent.get_attribute("aria-expanded") == "true")
The XPath above is relative to the tree element and finds a closed treeitem containing the text “Reports.” If the label is a separate sibling or the component has different markup, inspect the DOM and adjust the relationship instead of broadening the locator to a global first match. If there is a stable item ID or test attribute, use that in place of text-based matching.
Wait for the child group when that is the meaningful outcome
Some applications update the state attribute before children finish rendering, or render children asynchronously. In that case, check both the parent state and the expected child group or child item. Re-find elements after a render if the framework replaces nodes.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
from selenium.webdriver.support import expected_conditions as EC
wait.until(lambda d: parent.get_attribute("aria-expanded") == "true")
child_group = wait.until(lambda d: parent.find_element(
By.CSS_SELECTOR, "[role='group']"
))
wait.until(lambda d: child_group.is_displayed())
# Optional stronger assertion when a known child should appear:
wait.until(EC.visibility_of_element_located(
(By.XPATH, ".//*[@role='treeitem'][.//*[normalize-space()='Quarterly']]" )
))
Use the postcondition that matters to the test. If the test is specifically about disclosure state, assert aria-expanded. If the user task depends on the newly revealed item, wait for that item to be visible as well.
Rank #2
- The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
- Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
- G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
- Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
- The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere
Java: the same state-driven interaction
For Java, use the same locator strategy and synchronization. This example uses Selenium 4’s Duration-based wait constructor and getDomAttribute to read the DOM attribute.
import java.time.Duration;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.WebDriverWait;
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
By closedParent = By.cssSelector(
"[role='tree'] [role='treeitem'][aria-expanded='false']"
);
WebElement parent = wait.until(d -> {
for (WebElement item : d.findElements(closedParent)) {
if (item.getText().contains("Reports")) return item;
}
return null;
});
List<WebElement> buttons = parent.findElements(
By.cssSelector("button,[role='button']")
);
WebElement control = buttons.isEmpty() ? parent : buttons.get(0);
wait.until(d -> control.isDisplayed() && control.isEnabled());
control.click();
wait.until(d -> "true".equals(parent.getDomAttribute("aria-expanded")));
For production tests, prefer an explicit, precise item locator over scanning all closed parents and comparing rendered text. The loop is shown to make the label scoping idea clear; a stable ID, data-testid, or reliable parent-label relationship is less ambiguous.
Choose the interaction level that matches the widget
Native WebElement click
Start with element.click() on the actual interactive element: usually a disclosure button, or sometimes the treeitem itself. It exercises the browser’s normal element interaction and is the clearest choice when the control is visible, enabled, and unobstructed.
The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Actions API for pointer geometry or hover
If the icon only appears on hover, the interaction depends on pointer position, or ordinary clicking is intercepted because of geometry, use Selenium’s Actions API to move the pointer and click. The Actions API is a lower-level interface for virtualized pointer, keyboard, and wheel input. First inspect overlays and wait for transitions; Actions should address a genuine pointer-interaction requirement, not mask a bad locator.
Rank #3
- Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
- Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
- Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
- Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
- Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
from selenium.webdriver.common.action_chains import ActionChains
ActionChains(driver).move_to_element(control).click().perform()
Keyboard activation for accessible trees
When the widget implements the documented tree keyboard pattern, focus the parent node and send ENTER to toggle it. Tree patterns also define arrow-key navigation and expansion behavior, but exact handling depends on the widget. Use the keyboard path when it reflects the intended user interaction or when the control is not reliably pointer-targetable.
from selenium.webdriver.common.keys import Keys
parent.send_keys(Keys.ENTER)
wait.until(lambda d: parent.get_attribute("aria-expanded") == "true")
Do not make JavaScript arguments[0].click() the default fix. It can bypass native hit-testing and the user-input path the test is meant to exercise. It can help diagnose whether a click handler exists, but a successful JavaScript-triggered event does not establish that a real user can reach the control.
Wait for a condition, not an arbitrary delay
An explicit wait polls for a specified condition and proceeds when it becomes true or the timeout expires. For tree expansion, useful conditions include the parent state becoming true, a child group becoming visible, or a known child appearing. A fixed sleep can be too short on a slow render and waste time on a fast one.
Free tools Windows power users keep installed
One-click scans. No signup required.
Use one synchronization strategy consistently. Selenium warns that mixing implicit and explicit waits can produce unpredictable timing. In a test suite using explicit waits, keep the implicit wait at its default (zero) and add waits around the particular state transitions the test depends on.
Rank #4
- Computer mouse for easily navigating a computer interface; click, scroll, and more
- USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
- High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
- 3 buttons offer effortless fingertip control
- Plug-and-go ready for instant use
- Wait for the tree or node to exist before trying to locate descendants.
- Wait for the control to be displayed and enabled before clicking.
- After the click, wait for the expanded state or expected child content.
- Prefer conditions tied to the UI over sleeps calibrated to one machine.
Troubleshoot clicks that fail or open the wrong branch
NoSuchElementException
The tree may not have rendered yet, the branch may be created only after another action, or the selector may not match the actual markup. Wait for the tree first, inspect the live DOM, and then locate the branch. Confirm whether the accessible state is on a treeitem, row, or cell before assuming a selector.
ElementClickInterceptedException
A modal, sticky header, tooltip, overlay, or animation may cover the target. Check what occupies the click location, wait for the obstruction or transition to finish, and make sure the locator points to the real button rather than a decorative icon. Scroll the control into view only when it is outside the viewport; if pointer movement matters, use Actions after the page is ready.
StaleElementReferenceException
Expansion can trigger a framework render that replaces the node represented by your saved element. Re-locate the parent and child group after the transition rather than continuing to use references captured before the DOM update.
The click returns, but no children appear
Check whether the item is actually a parent. In the ARIA tree pattern, leaf treeitems omit aria-expanded; an absent state is not necessarily a failed expansion. For a parent, verify the state change and then wait for the child group or known child to render. If the application fetches children over the network, wait for the resulting UI condition rather than assuming the click and render are synchronous.
The wrong branch opens
Scope the locator to the correct tree container and match the intended visible label or stable node attribute. Avoid selectors that choose the first matching arrow globally, especially with nested trees or repeated labels.
Best Value
- 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
- 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
- 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
- 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
- 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.
The test is flaky
Remove arbitrary sleeps, wait on the state transition, and avoid mixing implicit and explicit waits. Also confirm that the target is not re-created during rendering and that the test is not locating an off-screen duplicate or hidden template.
Design the test around observable behavior
Separate locating, acting, and verifying so a failure says what went wrong. A robust test should establish that the intended node exists, that it is a parent in a closed state, that the intended control is interactable, and that expansion produces the expected state or content.
Do these 3 things before closing this tab:
1Scan for outdated or missing drivers - takes under a minute2Clear out junk files and repair common Windows errors3Fix the driver behind crashes, sound loss and screen glitches- Locate: scope to the intended tree and use a stable identifier or semantic relationship to the label.
- Act: click the nested disclosure control when available; otherwise use the interactive parent element.
- Verify: wait for
aria-expanded="true", a visible child group, or the specific child needed by the next step. - Recover from rerender: fetch fresh elements after expansion if the application rebuilds the tree DOM.
ARIA state is useful both as an accessibility signal and as a testable state contract, but it should not replace checking the task outcome when the test depends on rendered children. Conversely, a visible child alone may not prove that the correct node was toggled if the page has duplicates; scope the assertion to the intended parent.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server, not a Selenium replacement for clicking a tree control or asserting interactive behavior. It is useful when the goal is to capture a page after it is accessible to the service, rather than to drive this Selenium interaction. A single GET request returns an image or PDF; its clean-shot handling can accept consent banners and remove supported popups and chat widgets before capture.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and 1,000 screenshots per month are free with no card; paid plans start at $5 for 3,000. Learn about ScreenshotNeo or sign up for 1,000 free screenshots a month, with no card.
Frequently asked questions
Should I click the arrow icon or the whole tree row?
Click the element the widget exposes as interactive. If the row contains a nested button or role=button disclosure control, target that control rather than a decorative SVG or span.
Recommended Free Tools
Can I use XPath to find the branch by its text?
Yes. XPath can express a relationship between a treeitem and its label, but keep it relative to the correct tree and avoid absolute, positional paths. Prefer a stable ID or concise CSS selector when available.
What does it mean if a treeitem has no aria-expanded attribute?
It may be a leaf. In the ARIA tree pattern, parent nodes expose expanded state while leaf nodes omit it.
Is JavaScript click a good workaround for an intercepted click?
Not as a default. First identify the obstruction or wrong target; JavaScript click may bypass the same hit-testing and input path your test should verify.
Quick Recap
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

