I am new to web scraping and I wanted to use the find_element function to find a specific element after already using find_elements, but whenever I try to use it I keep getting this error: list’ object has no attribute ‘find_element’.
here is the code
driver = webdriver.Chrome()
url = "https://destinytracker.com/destiny-2/profile/psn/4611686018440125811/matches?mode=crucible"
driver.get(url)
crucible_content = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "div.trn-gamereport-list.trn-gamereport-list--compact")))
game_report = crucible_content.find_elements(By.CLASS_NAME, "trn-gamereport-list__group")
group_entry = game_report.find_element(By.CLASS_NAME, "trn-gamereport-list__group-entries")
i have tried these methods:
1.group_entry =WebDriverWait(game_report, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "trn-gamereport-list__group-entries")))
2. for group_entry in game_report:
group_entry = game_report.find_element(By.CLASS_NAME, "trn-gamereport-list__group-entries")
3. group_entry = game_report.find_element(By.CLASS_NAME, "trn-gamereport-list__group-entries")[1]
unfortunately, I still get the same error. it would be greatly appreciated if anyone could help.
2
Answers
Call
find_elements()
to get a list of all matching elements, then loop over that list and callfind_element()
on each item.Since you’re getting a list i.e game_report , try to iterate over the list and find the element the element.
You simply can’t call find_element method on the list