I made a program to download 64 invoices, it goes well until the ninth, but when it arrives in it selenium stops clicking without error
All elif get a different id and perform the same action with it, but when it arrives at the ninth elif it hangs, but if I start straight from 9 it works and hangs at 17, I would like to know why it hangs from 9 to 9
It stops at this snippet of code:
segunda_via = driver.find_element_by_xpath('//*[@class="card-vertical-align ng-scope"]')
segunda_via.click()
#sleep(10)
and this is the rest of the code, having 63 elif between the first if and the else, locking only at ninth:
while a < 64: #Mode chrome driver options chrome_options = Options () # location of donwloads download_dir="C: \ scrapy"
#Novas configurações
chrome_options.add_experimental_option('prefs', {
"plugins.plugins_list": [{"enabled":False,"name":"Chrome PDF Viewer"}],
"download": {
"prompt_for_download": False,
"default_directory" : download_dir
}
})
#Localizar webdriver no pc e entrar no site
driver = webdriver.Chrome('C:\scrapy\chromedriver', chrome_options=chrome_options)
driver.get('https://servicosonline.cpfl.com.br/agencia-webapp/#/login')
sleep(15)
element = WebDriverWait(driver, 600).until(EC.presence_of_element_located((By.ID, 'encontrarInstalacao')))
#Clicar no checkbox do email
email = driver.find_element_by_xpath('//*[@translate="@APP-COMMON-EMAIL"]')
email.click()
#Digitar email
username = driver.find_element_by_id('documentoEmail')
username.send_keys('email')
sleep(0.5)
#Digitar Senha
password = driver.find_element_by_id('senha')
password.send_keys('password')
sleep(0.5)
#Clicar botao para logar
sign_in_button = driver.find_element_by_xpath('//*[@valeutype="submit"]')
sign_in_button.click()
sleep(2)
element = WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.ID, 'selInstalacao')))
#Localizar botão Para procurar unidade
search_button = driver.find_element_by_xpath('//*[@type="search"]')
search_button.click()
sleep(0.5)
#Achar Unidades
if a == 1:
actions = ActionChains(driver)
actions.send_keys('25805681') # Pressionar o C
actions.perform()
teste = driver.find_element_by_xpath('//*[@class="ui-select-choices-row ng-scope active"]')
teste.click()
sleep(1)
elif a == 9:
#trocar nome e pasta do arquivo
os.rename('C:/scrapy/' + 'conta-completa.pdf','C:/scrapy/teste/' + '38085143.pdf')
#trocar nome de arquivos da pasta
original_dir = 'C:/scrapy/teste'
for n, file_name in enumerate(os.listdir(original_dir), 1):
full_path = os.path.join(original_dir, file_name)
if (os.path.isfile(full_path) and '{}_'.format(n) not in file_name):
os.rename(full_path, '{}/{}_{}'.format(original_dir, n, file_name))
actions = ActionChains(driver)
actions.send_keys('39615529')
actions.perform()
teste = driver.find_element_by_xpath('//*[@class="ui-select-choices-row ng-scope active"]')
teste.click()
sleep(1)
... goes to elif 64
else:
#trocar nome e pasta do arquivo
os.rename('C:/scrapy/' + 'conta-completa.pdf','C:/scrapy/teste/' + '4001760792.pdf')
#trocar nome de arquivos da pasta
original_dir = 'C:/scrapy/teste'
for n, file_name in enumerate(os.listdir(original_dir), 1):
full_path = os.path.join(original_dir, file_name)
if (os.path.isfile(full_path) and '{}_'.format(n) not in file_name):
os.rename(full_path, '{}/{}_{}'.format(original_dir, n, file_name))
sleep(2)
#Clicar no acessar
acessar = driver.find_element_by_xpath('//*[@class="btn btn-default btn-lg btn-block ng-scope"]')
acessar.click()
sleep(4)
element = WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.ID, 'btnPagar')))
#Clicar Botão Segunda Via
segunda_via = driver.find_element_by_xpath('//*[@class="card-vertical-align ng-scope"]')
segunda_via.click()
#sleep(10)
element = WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.ID, 'debitosPendentes')))
pdf = driver.find_elements_by_xpath('//*[@class="btn btn-default btn-segunda-via-aberta ng-scope"]')
driver.execute_script("arguments[0].click();", pdf[0])
sleep(2)
element = WebDriverWait(driver, 120).until(EC.presence_of_element_located((By.ID, 'btnVerContaCompleta')))
conta_completa = driver.find_element_by_id('btnVerContaCompleta')
conta_completa.click()
sleep(20)
a = a + 1
print ('Todas faturas Baixadas')
driver.quit()