skip to Main Content

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


  1. Call find_elements() to get a list of all matching elements, then loop over that list and call find_element() on each item.

    game_reports = crucible_content.find_elements(...)
    for game_report in game_reports:
        group_entry = game_report.find_element(...)
    
    Login or Signup to reply.
  2. Since you’re getting a list i.e game_report , try to iterate over the list and find the element the element.

    for element in range(len(game_report)):
         print(game_report[element].text)
    

    You simply can’t call find_element method on the list

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search