How to work with changing element id in the html code
morde last edited by
I am working in a ERP where the elements id are changing/rotating randomly. so if I am writing a code to locate a id, next time I run the selenium code it gets me error as the id changes by that time How to capture the ids everytime
Sadly, it sounds like using the ID is not an option in this scenario A lot of websites implement security to prevent automating. While this makes your job more difficult it does improve the security of the application. So what can be done to bypass these security tricks? Use a different unique constant for that element This could mean using the class, xpath, class and xpath, or a massive variety of other identifiers in an attempt to identify the element you are wanting. This is a lot easier than you might think. A good example would be to create a list of all links, narrow down the list of links based on their classes and then iterate through the remaining list until it contains the text you are looking for. Use a different method than UI Automation Depending on what you are attempting to accomplish with the testing (Does the button work or does the process work?) you could always bypass the UI as a whole and just use HTTP requests to simulate the users. Some applications this might be impossible to do but it is typically speaking a lot faster, smoother and far less maintenance work. Also, it is very simple to record HTTP using applications like fiddler. Have adjustable security settings within the configuration This can be a massive pain for developers but it is extremely useful feature for secured websites. By implementing a configuration that optimizes the site for automation it will allow the automation team to easily and more efficiently build their scripts. However this causes drawbacks in the sense that it is a possible security issue and convincing people the need for this might be an overwhelming, drawn out task that ends up getting done quite poorly. And a cheat sheet to help This cheat sheet will assist in locating the XPath and CSS of the elements. Depending on the browser you should typically choose CSS over XPath (Performance reasons) if ID and such is not an option. This especially applies to IE. TL;DR You have many options just not that many good ones. It will increase the processing power required to performed your duties and likely slow down testing (Unless you bypass the UI which will be more efficient). However, it is very possible.