Python Forum

Full Version: Going through HTML table with selenium
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello Team,

I am trying to iterate through a webpage that contains a table, I am trying to access the first column of that table and then click on the save button to download the file:


table_id = "//body/div[@id='contents']/div[@id='main']/div/table[1]"
        table = driver.find_element(By.XPATH, table_id)
        rows = table.find_elements(By.TAG_NAME, "tr")

        k = 0
        #files_2b_downloaded = []
        #soup = BeautifulSoup(webPage.text,'html.parser')
        
        for row in rows[4:]:
            cells = row.find_elements(By.TAG_NAME, "td")
            if cells:
                image_elements = cells[0].find_elements(By.TAG_NAME, "img")
                image_to_click = image_elements[0]
                link_element = cells[0].find_element(By.TAG_NAME, "a")
                filename = link_element.get_attribute("href")
                file_2b_downloaded = filename.split("=")[-1]
                image_to_click.click()
this cell contains 3 to 4 images and is the first image the one I need to click on, but after the first iteration it shows empty and doesn't go through the if, what could be wrong?
what is the URL?
(Sep-26-2023, 06:46 PM)Larz60+ Wrote: [ -> ]what is the URL?

It is an intranet application, therefore, cannot be accessed from outside the company. Sorry about that.
I was able to resolve it by using python code to download the file, instead of clicking.