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
11 changes: 11 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 @@ -140,6 +140,17 @@ describe('utils', function () {
assert.strictEqual(textNode, getElementByXpath(element));
});

it('should return optimised path for child of element with id when optimised = true', function () {
const element = getElementXPath(
$fixture.find('#btn22')[0].parentNode.children[0],
true
);
assert.ok(
element.indexOf('@id') > 0,
'expected optimised xpath to use @id shortcut for ancestor'
);
});

it('should return correct path when element is comment node', function () {
const comment = $fixture.find('#comment')[0];
const node = document.createComment('foobar');
Expand Down