How to handle object xpath which is indicating different objects when we scroll?

Below is the xpath I am using to identify a checkbox:

((//div[contains(@class,‘container-body’)])[1]//div[contains(@class,‘header-row’)][1]//div[contains(@class,'BOOLEAN ')]/dynamic-field/div)[2]

So it is successfully locating the object. But if we scroll within the page then its starts indicating different check box, which gets visible on scrolling. Though the required check box is also visible there. We cannot use id as well, as this is for SFDC Conga page and its not a static id.
Please suggest some work around here.,

I’m sure you don’t want a workaround, you want a working solution – there’s difference.

Your problem is twofold.

  1. That XPath is brittle. It’s too reliant on a lengthy document tree leading to the target element (the checkbox).

  2. When you scroll, I imagine more page data is received which modifies the document tree and breaks the XPath in #1… because it’s so brittle.

For anyone to help you here, you need to provide more information. To help yourself, make that XPath less brittle.

1 Like

Hi @Russ_Thomas

Thanks for your response.
That is exactly the query that we have ‘how to make the Xpath less brittle?’ . We are not able to do anything here as there is no static locator available in the page Initially we tried out with id but that is also changing.
See the enclosed screenshot
Please suggest what more Information can we share.

I doubt those are the only options available.
You can start by learning more abouth xpath:

and further search about how you can optimize such.
note that, the xpath locators are not the only ones available into this universe, you can use also css or attribute locators, or even js.