Skip to content

fix(sdk-trace-web): pass optimised parameter recursively in getElementXPath#6430

Closed
slegarraga wants to merge 1 commit intoopen-telemetry:mainfrom
slegarraga:fix/get-element-xpath-optimised-param
Closed

fix(sdk-trace-web): pass optimised parameter recursively in getElementXPath#6430
slegarraga wants to merge 1 commit intoopen-telemetry:mainfrom
slegarraga:fix/get-element-xpath-optimised-param

Conversation

@slegarraga
Copy link
Copy Markdown

Fixes #6323

Problem

getElementXPath hardcodes false for the optimised parameter in the recursive call to traverse parent nodes:

xpath += getElementXPath(target.parentNode, false); // should be optimised

This means when optimised=true, ancestor nodes with IDs are not used as shortcuts, producing incorrect/longer XPaths.

Fix

Pass the optimised parameter through the recursive call:

xpath += getElementXPath(target.parentNode, optimised);

Example

Given <body id="body-id"><div></div></body>:

  • Before: getElementXPath(div, true)/html/body/div (ignores body's id)
  • After: getElementXPath(div, true)//*[@id="body-id"]/div (uses id shortcut)

…tXPath

The optimised parameter was hardcoded to false in the recursive call,
preventing ancestor nodes from using ID-based shortcuts when optimised
mode was enabled.

Fixes open-telemetry#6323
@slegarraga slegarraga requested review from a team as code owners February 19, 2026 23:49
@linux-foundation-easycla
Copy link
Copy Markdown

CLA Not Signed

@pichlermarc
Copy link
Copy Markdown
Member

closing as duplicate of #6335

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

getElementXPath does not pass parameter optimised recursively

2 participants