[Python] Python Selenium find nested element

Discussão em 'Python' iniciado por Stack, Agosto 22, 2025.

  1. Stack

    Stack Membro Participativo

    on this page I want to parse few elements. [​IMG]

    I would like to get text in circles and use attribute value to click sometimes. That code returns anything. With this code I want to get all attribute values. (54,68,128,157 and 170)

    izbira_UE = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//ul[@id='facetUE']")))
    for ena_UE in izbira_UE:
    print(ena_UE.find_element(By.TAG_NAME, "li").get_attribute('data-val'))


    But this code finds attribute of @class. That is 'cnt'. How can I get text of this element. If I add the .text() after get_attribute, I get the TypeError: 'str' object is not callable. How can I get both text (one in "a" element (name of the city) and also the number inside [](in "div" element)?

    izbira_UE = wait.until(EC.visibility_of_all_elements_located((By.XPATH, "//*[@id='facetUE']//*[@data-val='54']")))
    for ena_UE in izbira_UE:
    print(ena_UE.find_element(By.TAG_NAME, "div").get_attribute('class'))


    Thanks for your help,

    Continue reading...

Compartilhe esta Página