Skip to main content
hirushiharant0001
December 28, 2023
Solved

How to use xPath as a browser action selector, which is changing dynamically

  • December 28, 2023
  • 8 replies
  • 0 views

I am developing browser automation for a website, using xPaths as the element selector for browser interactions. Whenever the website I am working on gets updated, the element xPaths change randomly. Is there any way to overcome this issue, or do I have to test and modify the browser action xPaths every time there is an update to the website?

Best answer by sriramk5349

Hi [mention:c313b468f82b40aabe4c80d90a89b0d5:e9ed411860ed4f2ba0265705b8793d05] ,

Whenever possible, try to use unique attributes in your XPath expressions. Instead of relying solely on the position or structure of an element, use attributes like id or class that are less likely to change during updates. Utilize XPath functions to create more flexible and resilient expressions. Functions like contains(), starts-with(), and ends-with() can be helpful like below.

//div[contains(@class, 'partialClassName')]

//input[starts-with(@id, 'prefix')]

if you use full xpath, It is the direct way to find the element, but the disadvantage of the absolute XPath is that if there are any changes made in the path of the element then that XPath gets failed.

8 replies

venkatrea696188
December 29, 2023

I suggest you to pick an other selector which not gonna alter with time Like CSS SELECTOR

https://docs.appian.com/suite/help/23.4/rpa-9.6/selectors.html

hirushiharant0001
December 29, 2023

Hi Venky,

I have tried that, and other selectors are changing too. I felt more accurate detection using xPath and Link Text selectors compared to other options. Some elements don't have values for selectors such as name and tag.

rithanir5887
January 10, 2024

Hello [mention:c313b468f82b40aabe4c80d90a89b0d5:e9ed411860ed4f2ba0265705b8793d05] ,

May I know how you configured your XPath? Or what type of updates in the website is making your XPath change dynamically?

Because, when we configure XPath,

i) we mostly should avoid indexing which may change on any updates in the website and 

ii) specify in which tag you want to search ( example:    //div[@id='name']   ) .

But if your XPath is unique, then I would like to know more about how you are configuring XPath and what type of updates are happening in your website.

komalj3844
January 10, 2024

May I know how you fetch the xpath , What i usually follow is right click on the position for which i want the xpath and select copy and i get the option to select full xpath . Would suggest to try this and see if any difference from your way

rithanir5887
January 11, 2024

Hello [mention:15d45cf742934b33a0c4bac62721efa4:e9ed411860ed4f2ba0265705b8793d05] ,

But wouldn't the full XPath change, when changes are made in the website?

hirushiharant0001
January 11, 2024

Hi [mention:07e65f9e440e41fdad9b01615263f43d:e9ed411860ed4f2ba0265705b8793d05] & [mention:15d45cf742934b33a0c4bac62721efa4:e9ed411860ed4f2ba0265705b8793d05] ,

Thanks for the reply.

The website has dynamic field. So it is using table layout.


The xPath i am getting is //*[@id="field_1359544387"]. Whenever there is any maintenance, the xPath id is changing. I couldn't find any pattern. It is random. 


Then now I am trying the full xPath which is looks like /html/body/div[3]/div[2]/table/tbody/tr/td/div[1]/form/div[6]/table[8]/tbody/tr[208]/td/select. There is no maintenance after the changes. 


I hope the full xPath will not change like xPath.