Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/opentelemetry-sdk-trace-web/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ export function getElementXPath(target: any, optimised?: boolean): string {
}
let xpath = '';
if (target.parentNode) {
xpath += getElementXPath(target.parentNode, false);
xpath += getElementXPath(target.parentNode, optimised);
}
xpath += targetValue;

Expand Down
21 changes: 21 additions & 0 deletions packages/opentelemetry-sdk-trace-web/test/window/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ describe('utils', function () {
);
});

it('should use ancestor id when optimised recursively', function () {
const body = document.querySelector('body');
if (!body) {
throw new Error('Missing document body');
}

const container = document.createElement('div');
container.id = 'body-id';
const inner = document.createElement('div');
container.appendChild(inner);
body.appendChild(container);

try {
const element = getElementXPath(inner, true);
assert.strictEqual(element, '//*[@id="body-id"]/div');
assert.strictEqual(inner, getElementByXpath(element));
} finally {
body.removeChild(container);
}
});

it(
'should return correct path for element with id and surrounded by the' +
' same type',
Expand Down