Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To click a nested node reliably, locate the tree (or a stable parent row), search for the descendant with a relative CSS selector or XPath, wait for the application state that makes the control visible and enabled, and click the current element reference. If expanding a branch rerenders the tree, wait for the old node to become stale and locate the parent and target again.

The reliable sequence

  1. Inspect the rendered DOM and identify the actual interactive element: it may be a <button>, <a>, or another control inside the visible row.
  2. Choose stable attributes such as data-* values, accessible labels, IDs supplied by the application, or distinctive classes. Avoid generated positional indexes when a stable attribute exists.
  3. Locate the tree or a unique ancestor first. Use that WebElement as the search root for the nested node.
  4. Wait for the application condition you need—such as a branch being expanded, a target appearing, or an overlay disappearing.
  5. Click the element currently attached to the DOM. After a rerender, discard saved references and locate them again.

Selenium’s Waiting Strategies guide notes that navigation readiness does not mean JavaScript has finished adding or changing controls. Its recommendation is to wait for the condition required by the next action, not merely for page load.

Before writing the locator

Inspect the real interactive control

A tree row that looks clickable may only contain text, while a nested button or link receives the click. In browser developer tools, expand the branch and inspect the element that handles the event. Check whether the widget uses native markup or ARIA roles such as role="tree", role="treeitem", and aria-expanded. These attributes are clues, not universal selectors; use the structure your application actually renders.

Prefer stable relationships

When the target label is unique within a known branch, express that relationship instead of searching the entire document. A relative XPath beginning with .// searches below a parent WebElement. Selenium documents descendant lookup in its WebElement API. CSS selectors and XPath are both supported locator strategies; the locator documentation describes the available forms.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.

Python example: scope the search and wait

The following is a template. Replace every illustrative selector with attributes from your page.

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

# Create the driver appropriate for your environment.
driver = webdriver.Chrome()
driver.get("https://example.test/tree")

wait = WebDriverWait(driver, 10)

# Replace [data-tree] with the tree's stable locator.
tree = wait.until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, "[data-tree]"))
)

# Relative XPath is important: the leading dot scopes the search to tree.
target = wait.until(lambda d: tree.find_element(
    By.XPATH,
    ".//button[normalize-space()='Target node']"
))

wait.until(EC.element_to_be_clickable(target)).click()

visibility_of_element_located waits for a displayed element, while Python’s element_to_be_clickable checks that an element is visible and enabled. The expected-conditions API documents these conditions. This example is an explanatory template, not a universal tree selector.

When a parent or branch must be expanded first

Many trees render children only after a disclosure control is activated. Treat expansion and target selection as separate state transitions. Locate the current branch, click its expand button, then wait for an application-specific signal such as aria-expanded="true" or the appearance of a child element.

branch = wait.until(EC.presence_of_element_located(
    (By.CSS_SELECTOR, "[data-node-id='reports']")
))

expand = branch.find_element(By.CSS_SELECTOR, "button[aria-expanded]")
if expand.get_attribute("aria-expanded") != "true":
    wait.until(EC.element_to_be_clickable(expand)).click()
    wait.until(lambda d: branch.get_attribute("aria-expanded") == "true")

target = wait.until(lambda d: branch.find_element(
    By.XPATH, ".//button[normalize-space()='Monthly report']"
))
wait.until(EC.element_to_be_clickable(target)).click()

Your widget may put aria-expanded on a tree item rather than its button, or may expose a different completion signal. Wait for the state your application changes, not for an arbitrary delay.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Handling rerenders and stale elements

Expanding a node can replace the entire tree subtree. A saved tree, branch, or target then points to a detached DOM node and Selenium raises StaleElementReferenceException. Wait for the old reference to become stale when that is useful, then reacquire from locators.

old_tree = wait.until(EC.presence_of_element_located(
    (By.CSS_SELECTOR, "[data-tree]")
))

old_expand = old_tree.find_element(
    By.CSS_SELECTOR, "[data-node-id='reports'] button[aria-expanded]"
)
wait.until(EC.element_to_be_clickable(old_expand)).click()

# Use this only when the application replaces the old tree element.
wait.until(EC.staleness_of(old_tree))

# Locate fresh elements after the rerender.
new_tree = wait.until(EC.visibility_of_element_located(
    (By.CSS_SELECTOR, "[data-tree]")
))
new_target = wait.until(lambda d: new_tree.find_element(
    By.XPATH, ".//button[normalize-space()='Monthly report']"
))
wait.until(EC.element_to_be_clickable(new_target)).click()

If the original tree remains attached and only its children change, staleness_of may never become true. In that case, wait for the child or attribute that proves expansion completed, then reacquire the target anyway.

Choosing CSS or XPath

Need Useful approach Guidance
Stable ID or data attribute CSS, for example [data-node-id='reports'] Usually concise and directly tied to application markup.
Text or a relationship Relative XPath, for example .//button[normalize-space()='Monthly report'] Scope it beneath a known parent and avoid brittle absolute paths.
Several matching rows Parent plus a distinguishing descendant Do not rely on nth-child unless ordering is an explicit contract.
Accessible tree widget ARIA attributes combined with the real control Verify which element receives the click; a visual row is not always interactive.

Use the rendered DOM, not a framework’s source component names. A selector that works before expansion may stop matching after virtualization or rerendering.

Waits that prevent flaky clicks

Use explicit conditions for each transition

An explicit wait polls until a chosen condition succeeds or the timeout expires. Examples include presence, visibility, clickability, a changed attribute, a child count, or staleness. Set the timeout according to the application’s normal worst case and keep the condition specific.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Do not mix implicit and explicit waits

Selenium warns: “Do not mix implicit and explicit waits. Doing so can cause unpredictable wait times.” Keep implicit waiting disabled (the default) when your test uses deliberate explicit waits, or establish one consistent policy across the suite.

Why fixed sleeps fail

A fixed sleep can finish before a slow render and waste time on a fast run. Replace it with a condition tied to the next action: an expanded attribute, an unobstructed button, or a newly rendered descendant.

Troubleshooting common failures

NoSuchElementException

  • The branch has not rendered yet: wait for the condition that creates it.
  • The search is scoped to the wrong parent: confirm that the parent contains the target in the current DOM.
  • The XPath is absolute or missing its leading dot: use a relative expression such as .//... beneath the parent.
  • The target is inside an iframe or shadow root: switch to the correct browsing context or use the component’s supported shadow-DOM access before locating it.

StaleElementReferenceException

A rerender detached the saved element. Wait for staleness if appropriate, then locate the tree, branch, and target again. Never keep retrying a stale object indefinitely.

Not clickable or not interactable

Check that the element is displayed and enabled, that its branch is expanded, and that an animation or overlay has finished. The clickable condition does not know whether an application-specific mask still intercepts pointer input.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

ElementClickInterceptedException

Inspect the page at the failure moment. A sticky header, consent dialog, loading mask, or another element may cover the control. Wait for that obstruction to disappear, close it through the supported UI, or target the actual button rather than its surrounding row. Do not assume a JavaScript-triggered click is equivalent to a real user click.

The test times out intermittently

Capture the DOM and relevant attributes when the timeout occurs. Confirm whether the application took a different branch, virtualized the row out of view, or replaced the parent. Increase the timeout only after identifying the state that is genuinely slow.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability practices

  • Use one shared WebDriverWait configuration per test or page object rather than scattering arbitrary delays.
  • Keep locators narrow: a parent-scoped query reduces accidental matches in large trees.
  • Wait for semantic state changes instead of polling every descendant repeatedly.
  • Reacquire after known rerenders, but do not repeatedly reload the page to hide synchronization defects.
  • Log the locator, branch state, and exception. This makes a selector regression distinguishable from a timing problem.
  • Keep the test’s browser viewport and data setup deterministic when virtualization or responsive layout changes which nodes are rendered.

Or skip the browser setup

If your goal is a clean image or PDF of a page rather than an interactive Selenium assertion, ScreenshotNeo returns a screenshot from one GET request. It accepts cookie and consent banners like a visitor, removes more than 60 known consent platforms plus newsletter popups and chat widgets before capture, and bills only clean shots. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.

See the ScreenshotNeo documentation for all options, including full-page lazy-image loading, element capture, device presets, custom waits, CSS and JavaScript, headers, cookies, geolocation, PDF settings, caching, signed links, asynchronous jobs, bulk capture, and usage reporting.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

cURL

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

Python

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
r.raise_for_status()
open("shot.webp", "wb").write(r.content)

Node.js

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const fs = await import('node:fs/promises');
await fs.writeFile('shot.webp', Buffer.from(await res.arrayBuffer()));

The Free plan includes 1,000 screenshots each month with no card. Paid plans start at $5 for 3,000 shots; every feature is included on every plan. Create a free ScreenshotNeo account.

FAQ

Should I click the tree row or its expand button?

Click whichever element the application uses for the intended action. Expansion and selection are often separate controls; inspect event handlers and accessible markup instead of assuming the whole row is clickable.

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Can I use JavaScript to force the click?

Use native WebDriver interaction first. A script-dispatched click can bypass hit testing and conceal overlays, so it may not represent the behavior a user or production browser experiences.

What timeout should I choose?

Choose a limit longer than the application’s normal slow render, then fail with diagnostic information. There is no universal Selenium timeout for every tree or environment.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Frequently Asked Questions

How do I know whether a rerender occurred?

Compare the saved element reference with the DOM after the action, or wait for staleness when the application replaces the parent. A stale-reference exception is direct evidence that the old node detached.

Why does a selector work manually but fail in Selenium?

Manual inspection may occur after expansion or after an overlay disappears. Ensure Selenium waits for the same rendered state and uses the current browsing context.

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.