CSS/XPATH selector random page changes using python's dictionary



  • 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: [button1, css_selector, xpath_selector, page_found, description]



  • 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']"}}



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2