How to use i no for value in a function?

Asked

Viewed 58 times

0

I have the following code:

select = Select(driver.find_element_by_id('Identificador')).select_by_visible_text('Maio/2019')
form = driver.find_element_by_name('Formulario')
driver.find_element_by_xpath("//form[@name='Formulario']/input[@type='submit'][@value='Ok']").click()

I’d like to automate that with a for for several months and years.

month = ["Janeiro", "Fevereiro", "Março", "Abril", "Maio", "Junho", "Julho", "Agosto", "Setembro", "Outubro",
         "Novembro", "Dezembro"]

year_today = datetime.date.today().year

year = range(2007,year_today,1)

for i in year:
    for j in month:
        print('Downloading',j,i)
select = Select(driver.find_element_by_id('Identificador')).select_by_visible_text('Maio/2019')
form = driver.find_element_by_name('Formulario')
driver.find_element_by_xpath("//form[@name='Formulario']/input[@type='submit'][@value='Ok']").click()

How I replace "May/2019" with values of Month and year?

1 answer

2


Use string concatenation to cast a year

select = Select(driver.find_element_by_id('Identificador')).select_by_visible_text(j+'/'+str(i))
  • Ah, I understand how it works! Thank you! I just needed to change the year for i. Thanks!

  • I’m glad you made it!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.