1

With reference to your reply to question (Find an element where data-tb-test-id attribute is present instead of id using Selenium and Python) can you please help with how to add a custom html attribute for test locators in selenium.

  • The webmaster would add them to the markup... you can add any attribute you like to an HTML element. Could be a simple as "
    " The key is to be sure they are unique. You do that in cases where for some odd reason element ids are not unique, or they aren't used by all elements on the web site. (the event will be caught through event bubbling or added specific but not id-based/non-specific event handlers... the event will have details about the event's source... Ex: https://developer.mozilla.org/en-US/docs/Web/API/Event/target )
    – pcalkins Jun 02 '22 at 18:33
  • btw, this makes things much easier for Selenium coders... how many times I've seen these long path-based locators posted here, or even ones with parent/child calls just to get at a certain value/row/column. If they all have IDs your locators become very simple and easy to read right from the browser's inspector. – pcalkins Jun 02 '22 at 18:45

0 Answers0