Home > front end >  partial text in xpath
partial text in xpath

Time:07-14

<a 
    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"]')))

CodePudding user response:

Xpath can be a hassle sometimes, I recommend using the CSS selector method to accomplish this:

element = driver.find_elements_by_css_selector("[aria-label='1100-1200-200167-620038']")

You could them use the element in your visibility_of_element_located method.

CodePudding user response:

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