I am trying to extract the url from an href that is very specific, this site has many html routes that are VERY! similar and the only way to extract this url is by an XPATH built in the way I am doing it.
But the big issue is the following, it changes all the time, part of the label is static but the other is dynamic and it is kind of random
The html looks like this: NOTE: page_name ="Laura"
is a name I can select
# Option 1 <span label="answer by Laura to Charles"> # Option 2 <span label="answer by Laura to Nina"> # Option 3 <span label="answer by Laura to Maria"> <div > <a href="www.thisisawebsite.otherthings.blabla...> # Option n <span label="answer by Laura to THIS COULD BE ANY RANDOM NAME"> <div > <a href="www.thisisawebsite.otherthings.blabla...>
I have tried different options:
get_comment = WebDriverWait(self.driver, 2).until( EC.presence_of_all_elements_located(( By.XPATH, r'//span[contains(text(), "answer by {}")]/div/a'.format(page_name))) )[0].get_attribute('href')
Other try:
get_comment = WebDriverWait(self.driver, 2).until( EC.presence_of_all_elements_located(( By.XPATH, r'//span[(@label="answer by {}")]/div/a'.format(page_name))) )[0].get_attribute('href')