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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

For Android tests using Appium’s UiAutomator2 driver, set allowInvisibleElements to true. UiAutomator2 filters nodes whose displayed value is false from page source and XPath by default; enabling this setting includes them. If the node is still missing, check hierarchy compression and whether the app exposes it to accessibility at all. On iOS with XCUITest, the visibility attribute comes from the accessibility layer, so the Android setting does not apply.

First identify what “visible=false” means

Appium’s page source is a driver-provided representation of the app’s UI hierarchy; it is not a pixel-by-pixel record of everything drawn on screen. A node can be absent from that hierarchy, present with a false visibility attribute, or present with a true attribute even when it does not look visible to a person. Those cases have different causes and fixes.

  • Absent from page source: the driver may be filtering the node, compressing the hierarchy, or the application may not expose it as an accessibility element.
  • Present with displayed="false" on Android: UiAutomator2 has included the node, but its displayed metadata says false. To locate such nodes when they are filtered, enable allowInvisibleElements.
  • Present with visible="false" on iOS: XCUITest’s visibility value is read from the accessibility layer. Investigate the app’s accessibility hierarchy and identifiers rather than applying an Android capability.

Start by saving the page source and searching for the target’s text, resource ID, accessibility identifier, or nearby parent. This tells you whether to address driver filtering or accessibility exposure before changing selectors.

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

Expose invisible nodes with UiAutomator2

The UiAutomator2 driver documents allowInvisibleElements as false by default. With it set to true, nodes that are not visible are added to page source and can be found using XPath. The option changes what the hierarchy exposes; it does not make the element visible on the device or guarantee that an interaction with it is meaningful.

Set it when creating the session

For clients that support Appium’s settings capability syntax, include this capability in the session capabilities:

{
  "platformName": "Android",
  "appium:automationName": "UiAutomator2",
  "appium:settings[allowInvisibleElements]": true
}

Keep your app, device, and any other required session capabilities in the same object. Capability naming and parsing depend on the client and driver versions; if the setting is not applied during session creation, set it after the session starts instead.

Set it after session creation

Appium settings can be changed through the settings endpoint. In a client that exposes a settings method, the operation is conceptually:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
driver.update_settings({"allowInvisibleElements": true})
source = driver.page_source

The method name differs among client libraries. Use the library’s settings API to send allowInvisibleElements: true to the active session, then request page source and locate the element. Apply the change before the source snapshot or lookup you want it to affect. Check the UiAutomator2 README for the syntax supported by your installed driver: UiAutomator2 driver settings.

What changes and what does not

After the setting takes effect, refresh page source and inspect the target node. If it appears, you can locate it by XPath, although a native or accessibility locator is generally preferable. The setting can enlarge the hierarchy and expose nodes that are not actionable in the current app state. Keep it enabled only when your test needs those nodes, and assert the underlying behavior rather than treating discoverability as proof of visibility.

Use a locator that is stable for the platform

Once the node is exposed, choose a locator based on the attribute the app deliberately provides. Accessibility IDs and native selectors are generally more stable and faster than XPath, which Appium supports but documents as performance-sensitive.

Platform or attribute Locator to consider When it helps
Android accessibility description Accessibility ID, corresponding to content-desc Use when the app gives the control a stable accessibility description.
Android view identifier Resource ID Use when the target has a stable Android resource ID.
Android native hierarchy UiAutomator selector Use when native selector attributes fit the test better than a hierarchy-wide XPath.
iOS accessibility identifier Accessibility ID Use when the app exposes a stable identifier in its accessibility hierarchy.
Either platform XPath Use when the needed relationship or attribute is not available through a more direct locator; account for its performance sensitivity.

Do not assume an element’s on-screen label is also its accessibility identifier. Inspect the source or accessibility inspector output and use the actual attribute the app exposes.

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

Check other UiAutomator2 hierarchy settings

If the node remains absent after enabling allowInvisibleElements, inspect the other UiAutomator2 settings that affect hierarchy capture:

  • ignoreUnimportantViews controls hierarchy compression. If compression removes nodes relevant to your test, review this setting and try disabling it for diagnosis.
  • enableMultiWindows is relevant when the target may belong to a separate window rather than the main app window.
  • snapshotMaxDepth limits how deep the hierarchy snapshot goes. A target nested beyond the captured depth may not appear.

These settings address different reasons a node may not be represented. Change one at a time, recapture page source, and compare the result. Larger or less-compressed snapshots can be more expensive to inspect and may contain more nodes than your test needs.

Consult the installed driver’s documentation for accepted values and behavior: UiAutomator2 driver settings.

For XCUITest, inspect accessibility exposure instead

allowInvisibleElements is a UiAutomator2 setting, not a general Appium switch. XCUITest’s visible attribute is read directly from the accessibility layer; it is distinct from attributes such as accessible and nativeAccessibilityElement. Appium’s reference notes that the value is not available in XCTest itself and is read from accessibility: XCUITest element attributes.

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

If a control looks present but is missing from the iOS hierarchy, check whether the app exposes a real accessibility control, whether a parent masks its descendants, and whether the target has a stable accessibility identifier. A selector cannot find a node the active accessibility hierarchy does not expose; this usually calls for correcting the app’s accessibility structure, not repeatedly changing locator syntax.

Do not treat Android displayed metadata as a visual guarantee

On Android, displayed is driver/platform metadata, not a definitive test of what a person can see. In Appium issue #20516, a user reported that an element could remain in page source with displayed=true even when it was not visible to the human eye: Appium issue #20516. That issue is an example report, not a universal rule about every Android view or driver version.

For the behavior your test actually cares about, verify the app state, relevant bounds, and result of the interaction. For example, if a hidden button should not be usable, assert the application’s disabled or hidden state, or attempt the action and check the expected outcome. Do not make a test pass solely because a driver attribute says true or false.

Troubleshoot a missing or misleading element

  1. Identify the platform and driver. Confirm whether the session uses Android with UiAutomator2 or iOS with XCUITest. Do not apply an Android-only setting to an iOS session.
  2. Capture current page source. Search for the target and its parent. Record whether it is absent or present with a visibility value; those outcomes require different investigation.
  3. On UiAutomator2, enable allowInvisibleElements. Apply it at session creation or through the active session’s settings API, then fetch a fresh page source.
  4. Check hierarchy compression and capture bounds. Review ignoreUnimportantViews, multi-window handling, and snapshot depth if the node remains absent.
  5. Choose a direct locator. Prefer the exposed accessibility ID, Android resource ID, or native selector. Reserve XPath for cases where it adds necessary relationship or attribute matching.
  6. On XCUITest, verify accessibility exposure. Inspect whether the control exists in the accessibility hierarchy, whether a parent masks children, and whether the intended identifier is present.
  7. Assert app behavior, not just driver metadata. Confirm the state or outcome that matters to the user, particularly when Android’s displayed value conflicts with visual observation.

Common symptoms and fixes

Symptom Likely explanation Next step
Android node is absent from page source and XPath finds nothing UiAutomator2’s default filtering hides nodes marked not visible. Enable allowInvisibleElements, then retrieve fresh source.
Node remains absent after enabling the setting Hierarchy compression, a separate window, snapshot depth, or app accessibility exposure may be involved. Inspect the related settings and confirm the target exists in the app’s accessible hierarchy.
XPath locates a node but a tap does not behave as expected The node being locatable does not mean it is visible or actionable in the current state. Check state and bounds, and assert the outcome of the action.
Android reports displayed=true while the control looks hidden Driver metadata may not match human perception in that case. Verify the app state and action result instead of relying on that attribute alone.
iOS control appears on screen but is missing from source The accessibility hierarchy may not expose it, or a parent may mask descendants. Inspect the accessibility structure and add or correct a stable identifier in the app where appropriate.
XPath test becomes slow or brittle XPath requires hierarchy matching and is performance-sensitive. Switch to a stable accessibility ID, resource ID, or native selector when available.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

For browser-page screenshots rather than native Appium UI hierarchy inspection, ScreenshotNeo offers a one-request screenshot API. This is a separate tool: it does not change Appium’s element tree or make a native app element locatable. Its capture options include handling cookie consent and removing known consent platforms, newsletter popups, and chat widgets; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and the response indicates the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000.

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

Example cURL request for a browser-page capture; replace the URL and API key with your own. See the ScreenshotNeo API documentation for options and response details.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 screenshots a month with no card.

Frequently Asked Questions

Does allowInvisibleElements make a hidden Android control visible?

No. It exposes qualifying nodes in UiAutomator2’s page source and XPath lookup; it does not change the app’s rendering or interaction state.

Can I use this setting with XCUITest?

No. It is a UiAutomator2 setting. XCUITest visibility is read from the accessibility layer.

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

Should I use XPath for every newly exposed node?

No. Prefer a stable accessibility ID, Android resource ID, or native selector when the app provides one.

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.