pythonselenium-webdrivertagsgetattributefindelement

Find recurring attribute using selenium


I want to be able ,using the function get_attribute(), to get the value of a recurring tag in my html page.

This value appears a lot in the page.

I have tried using find elements by class name and then using the function get attribute but it doesn't work. I have tried using the find element function and this prints only the attribute of one variable while I want to be able to get all the variable inside the web page.

enter image description here

I want to get the id_documento attribute that appears a lot in the web page


Solution

  • You are on the right track.

    First, you need to find all elements (div in your case) that have the 'id_documento' attribute.

    Then you should iterate over located elements and extract the required attribute.

    elements = driver.find_elements(By.XPATH, '//div[@id_documento]')
    ids = [element.get_attribute('id_documento') for element in elements]
    

    Before doing this, ensure that your page is fully loaded.