Hi I am using selenium I want to find all values of hrefs present in webelement
links=profiles.find_elements_by_tag_name("a").get_attribute('href')
But it gives me error
AttributeError: 'list' object has no attribute 'get_attribute'
Hi I am using selenium I want to find all values of hrefs present in webelement
links=profiles.find_elements_by_tag_name("a").get_attribute('href')
But it gives me error
AttributeError: 'list' object has no attribute 'get_attribute'
You are getting list of a
tags so you can loop around and get your informations
a_list = profiles.find_elements_by_tag_name("a")
all_links = [item.get_attribute('href') for item in a_list]
all_links
will have list of urls you required
find_elements_by_tag_name(name) would return a list. Where as get_attribute(name) gets the given attribute or property of the WebElement. Hence the error:
AttributeError: 'list' object has no attribute 'get_attribute'
You need to iterate through the elements and extract the value of the href attributes as follows:
print([my_elem.get_attribute("href") for my_elem in profiles.find_elements(By.TAG_NAME, "a")])
Ideally, you need to induce WebDriverWait for the visibility_of_all_elements_located() and you can use either of the following Locator Strategies:
print([my_elem.get_attribute("href") for my_elem in WebDriverWait(profiles, 20).until(EC.visibility_of_all_elements_located((By.TAG_NAME, "a")))])