1

I am trying to download multiple files from a site using Selenium in python using the following code.

from selenium import webdriver
import pandas as pd
driver = webdriver.Chrome('chromedriver.exe')
driver.maximize_window()
driver.get('https://www10.goiania.go.gov.br/TransWeb/FuncionariosExportarPopUp.aspx?_=1590514086637')
element = driver.find_element_by_id('WebPatterns_wt12_block_wtMainContent_wtcboReferencia')
all_options = element.find_elements_by_tag_name("option")
selectYear = Select(driver.find_element_by_id("WebPatterns_wt12_block_wtMainContent_wtcboReferencia"))
link = driver.find_element_by_id('WebPatterns_wt12_block_wtMainContent_wtbtnGerar')
for option in all_options[:267]:
    print("Value is: %s" % option.get_attribute("value"))
    selectYear.select_by_value(option)
    link.click()
    time.sleep(5000)

But i'm getting this error and i do not know how to solve it.

TypeError: argument of type 'WebElement' is not iterable

This is the first time that i am using selenium.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

1

To download multiple files from the site https://www10.goiania.go.gov.br/TransWeb/FuncionariosExportarPopUp.aspx?_=1590514086637 using Selenium and selecting each option from the ReferĂȘncia you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategies:

  • Code Block:

    driver.get("https://www10.goiania.go.gov.br/TransWeb/FuncionariosExportarPopUp.aspx?_=1590514086637")
    select = Select(WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@id='WebPatterns_wt12_block_wtMainContent_wtcboReferencia']"))))
    for opt in select.options:
        opt.click()
        WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@value='Gerar']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    from selenium.webdriver.support.ui import Select
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

did you try this?

for option in range(len(all_options[:267])):
Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
Hari Aravi
  • 78
  • 3
0

Can you try assigning the list of elements for all_options to a list, for iteration to work.Then read the elements in for loop.

all_options = []