0

I have developed a Selenium script in python for a web application by extracting elements through Xpath with classname attribute. All the Xpaths are relative paths and not absolute paths. The script opens application in Chrome and works fine. But suddenly after few days, the Class name of an element changed (probably there was an update for web application, not sure). Due to this, my script is no longer able to find the element and hence failed an error.

This is a major drawback to my script drawback. I debugged it and managed to fix it by updating the classname to the present classname. But I feel it is not a proper solution as what if such changes happen again.

What happens if such a change happens again? Web application is not in my hands. I can only adjust script according to the application tag names and attribute names like class, div so on.

How could I probably handle such situations without ending up in an error? Is there a possibility that classname changes like that, if so, how would I overcome this dependancy?

I appreciate any advice on this. I can use only Python here.

Priya
  • 329
  • 3
  • 14
  • XPath is generally a fragile way of pointing at an element. Is there a reason you cannot find by ID or Class? – Jacob Miller Mar 01 '21 at 15:21
  • Because it has no other recognizable attributes other than 'class'. It is :
    Search Anyways I don't want to be specific to this element. But just want to know what is the alternative when such attribute names like classname or ID names changes.
    – Priya Mar 01 '21 at 15:41
  • Does the on-screen text remain the same (i.e. "Search")? If so, you can find elements by the text they contain. Check out this answer: https://stackoverflow.com/questions/12323403/how-do-i-find-an-element-that-contains-specific-text-in-selenium-webdriver-pyth – Jacob Miller Mar 01 '21 at 16:00

0 Answers0