The flow for something like that would look something like this:
- Take a screenshot of your full browser window
- Analyse the screenshot with your OCR software and let it return coordinates
- Interact with the element on that location, e.g. click item coordinates.
You say you want this because:
The Selenium script will always work without changing object locators in code
I think your thought process is interesting, but I think this is a dream and a lie. What if the application changes so that your OCR software finds two or more objects with the same text? Which one should it use? What if you have multiple elements that look the same, but the order has changed. Think about edit buttons. I think you will introduce new maintainability issues, while you increase the complexity of the testing framework hugely.
I assume you want to solve maintainability issues of Selenium tests, I would try:
- Learn to write good Selenium locators
- Centralize actions and locators in Page Objects
- Force developers to run and update test during development, not afterwards by testers. I would also let the developers create the happy-path tests and extend those by testers if needed.
- Write less Selenium tests, follow the guideline test automation effort spread as described by the test-pyramid.