Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a lot of functional tests in Python. As expected , they use a wide variety of css/xpath selectors .

I think I read somewhere that a practice is to have a dictionary where each selector would be stored. So, when a random selector in a random page changes for some reason, then theoretically it's selectors and/or attributes (id,name) would be changed only one time in this dictionary.

Is this possible? And if yes, what would be the structure of the dictionary/list/array? I am currently familiarizing myself with the theory of lists and dictionaries to see how to implement it. I think that one solution would be


share|improve this question

I think this is a general Python programming question rather than a test question.

As a general programming practice, it is a good idea to give a constant a name, especially if the constant is used more than once.

How you manage those names depends on your goal. You might do this:

XPATH = "xpath"
CSS = "css"
SELECTOR_TYPE = "selectorType"
SELECTOR = "selector"
// etc.

BUTTON1 = {SELECTOR_TYPE: XPATH, SELECTOR: "//input[@id='loginSubmitButton']"}
BUTTON2 = {SELECTOR_TYPE: XPATH, SELECTOR: "//input[@id='loginCancelButton']"}
USERNAME_FIELD = {SELECTOR_TYPE: CSS, SELECTOR: "form input[name='username']"}

I omitted page_found and description because you didn't explain what those are.

You might even want to put all those definitions in a dictionary so that you can pass them around as a group, like this:

login_selectors = { 'button1': {SELECTOR_TYPE: XPATH, SELECTOR: "//input[@id='loginSubmitButton']"},
                    'button2': {SELECTOR_TYPE: XPATH, SELECTOR: "//input[@id='loginCancelButton']"}
                    'username_field': {SELECTOR_TYPE: CSS, SELECTOR: "form input[name='username']"}}
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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