1

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:

id="j_id0:SiteTemplate:j_id255:new"

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.

1 Answer 1

1

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]")

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.