[Python] How to iterate through <tbody> with Selenium in Python?

Discussão em 'Python' iniciado por Stack, Abril 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to iterate through a list of <tr> elements in a <tbody> element. None of my print statements return anything and the output says the element is not found, but I don't know which element it is referring to. I know all of the elements the code is looking for are there from using inspect element, though. Why is this happening?

    from selenium import webdriver
    from selenium.webdriver.chrome.service import Service
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC

    service = Service(executable_path="chromedriver.exe")

    options = webdriver.ChromeOptions()
    options.add_argument(f"--user-data-dir=C:/Users/maxim/AppData/Local/Google/Chrome/User Data")
    options.add_argument(f'--profile-directory=Default')

    driver = webdriver.Chrome(service=service, options=options)
    driver.get("https://nepeto.com/retail")

    table = WebDriverWait(driver, 999999999999999999999).until(
    EC.presence_of_element_located((By.CLASS_NAME, "table is-hoverable products-table"))
    )
    print(table)
    tbody = table.find_element(By.TAG_NAME, "tbody")
    print(tbody)
    items = tbody.find_elements(By.TAG_NAME, "tr")
    print(items)
    for i, row in enumerate(items):
    print(f"Row {i}: {row.text}")


    The output is:

    DevTools listening on ws://127.0.0.1:61040/devtools/browser/91fd6ed5-42ba-4f0d-8af9-efd87354d971
    [5848:14048:0423/162715.616:ERROR:device_event_log_impl.cc(202)] [16:27:15.602] USB: usb_service_win.cc:105 SetupDiGetDeviceProperty({{A45C254E-DF1C-4EFD-8020-67D146A850E0}, 6}) failed: Element not found. (0x490)
    [5848:15576:0423/162716.894:ERROR:registration_request.cc(291)] Registration response error message: DEPRECATED_ENDPOINT
    Created TensorFlow Lite XNNPACK delegate for CPU.
    Attempting to use a delegate that only supports static-sized tensors with a graph that has dynamic-sized tensors (tensor#-1 is a dynamic-sized tensor).
    [5848:15576:0423/162746.588:ERROR:registration_request.cc(291)] Registration response error message: DEPRECATED_ENDPOINT
    [5848:15576:0423/162829.292:ERROR:registration_request.cc(291)] Registration response error message: DEPRECATED_ENDPOINT

    Continue reading...

Compartilhe esta Página