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?
Discussion posts and replies are publicly visible
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
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.
Hello Hirushiharan ,
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.
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
Hello Komal Jain ,
But wouldn't the full XPath change, when changes are made in the website?
Hi Rithani Vivekananthan & Komal Jain ,
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.
Hi Hirushiharan ,
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.
id
class
contains()
starts-with()
ends-with()
//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.
Hi Sri Ram Kaja ,
Thanks for the information. Will try the functions.