2

I recently recommended to my devs to add IDs to each element on the project I'm working to make automation more robust, they added in aria-uuid to each element. I cannot get anything to recognize these IDs! I'm wondering if it is even possible?

I'm using python/selenium.

I've tried identifying elements by ID, I've done CSS selectors and xpaths but they have had a history of breaking between new builds.

Relevant html:

input class="short ng-valid ng-not-empty ng-valid-min ng-valid-required" name="question_16" type="number" aria-uuid="question_16_input" ng-required="true" ng-min="0" ng-model="$ctrl.vault['question_16'].value"
def click_element_by_id(self, driver_init, id1, message1, delay1, halt):
  try:
      element = WebDriverWait(driver_init, delay1).until(EC.element_to_be_clickable((By.ID, id1)))
      element.click()
  except TimeoutException:
      if halt:
          assert_that(True, message1).is_false()
      else:
          print(message1)

Each time I get the assertion/timeout error

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Seamus3D
  • 33
  • 3

2 Answers2

1

Ideally, yes you should have been able to recognize each individual elements with respect to their aria-uuid to be used with Selenium provided the generated aria-uuid were static.

As per the HTML you have shared the generated aria-uuid seems to be dynamic. So aria-uuid alone won't help you. In these cases you have to use the aria-uuid along with the other attributes to uniquely identify the elements. To identify this element you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver_init, delay1).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.short.ng-valid.ng-not-empty.ng-valid-min.ng-valid-required[aria-uuid$='_input'][name^='question_']"))).click()
    
  • Using XPATH:

    WebDriverWait(driver_init, delay1).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='short ng-valid ng-not-empty ng-valid-min ng-valid-required' and contains(@aria-uuid, '_input')][starts-with(@name, 'question_')]"))).click()
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    Thank you for taking the time to answer my question. I was using CSS Selectors/xpaths before, but I had not considered using them in conjunction with the aria-uuids. Thank you! – Seamus3D Aug 22 '19 at 13:27
0

It should be possible with a CSS selector [aria-uuid='question_16_input']

kkrenzke
  • 60
  • 3
  • 8