We are using Selenium to test our UI and need to be able to find a reliable way to identify the elements of the page we are working with. I am working with a button and have defined an id to be able to reference it in my tests.

<apex:commandbutton id="new" styleclass="kbutton-white" value="New" action="{!togglePopup}"/>

However, when I load the page and inspect elements on it, I notice the id is shown as something like below:


Is there a way to reliably use id to find elements? If not, what other way can I use to reliably find elements on the page UI testing?

I have looked at finding by class but I may have multiple buttons with the same class and different texts and functionalities and I will need to use different class names to identify the buttons which is not good practice.

P.S.: We are testing a managed package and the development org, packaging org, and the test orgs will be different. Not sure if this is relevant.


This is the same basic problem as when trying to use jQuery or even basic JavaScript. What you need to do is to use find_element_by_css_selector instead:

content = driver.find_element_by_css_selector("[id*=new]")
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.