Selenium: Why would the id of an element change with every page load?

I’m using Python 3.11 on Windows 10 Pro and Selenium and chromedriver to enter data into a web site.

Help me understand this. Each time I run my Python program the id attributes of the HTML elements I want to use changes. Each id seems to be a random 12 character mix of letters and digits.

Is there a particular reason it does this?

I know pages can be dynamically generated by why change the element id each time to something random?

It could be because the dynamic generation software is trying to avoid name collisions without having to put any serious logic into the naming.

Or it could be because the site doesn’t want you to scrape it, and is trying to make that harder for you.

2 Likes