partial text in xpath

Issue

<a class="ui-autocomplete-row ui-corner-all"
    aria-label="(1100)Texas (PL1200/PC1030)- (200167)-Supplies: Other Supplies (620038): 1100-1200-200167-620038" 
    id="ui-id-7" tabindex="-1">
    (1100)- (PL1200/PC1030)-(200167)-Supplies: 
    Other Supplies (620038):
    <u><b>1100-1200-200167-620038</b></u>
</a>

In Xpath, I want to check if aria-label contains the value "1100-1200-200167-620038". It looks like there is a syntax error in the below statement:

element = wait.until(EC.visibility_of_element_located((By.XPATH,'//*[@aria-label="1100-1200-200164-620038"]')))

Solution

You can use two option like this:

  1. CSS Selector
element = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, 'a[aria-label*="1100-1200-200167-620038"]')))
  1. Xpath:
element = wait.until(EC.visibility_of_element_located((By.XPATH, '//a[contains(@aria-label, "1100-1200-200167-620038")]')))

Answered By – frianH

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published