How to use insist method in elementium

Best Python code snippet using elementium_python

endosso_main.py

Source:endosso_main.py Github

copy

Full Screen

1from ast import expr_context2from doctest import Example3from select import select4import sys, os5from datetime import date, datetime6import time7from time import sleep8from tkinter import E9from traceback import print_list10from unittest import defaultTestLoader11from attr import field # usar 'sleep(value)' ao invés de 'time.sleep(value)'12from selenium import webdriver13from selenium.webdriver.common.by import By14from selenium.webdriver.common.keys import Keys15from selenium.webdriver.support.ui import WebDriverWait16from selenium.webdriver.support import expected_conditions as EC17from selenium.webdriver.common.alert import Alert18from selenium.common.exceptions import NoSuchElementException19from selenium.webdriver.common.action_chains import ActionChains20from selenium.webdriver.chrome.options import Options21from selenium.webdriver.chrome.service import Service22from selenium.webdriver.support.select import Select23import pymssql24import endosso_functions as EF25import db26import globalconf as GC27# from pyUFbr.baseuf import ufbr28from unidecode import unidecode29import glob30def initializeRpa(rs):31 conn = pymssql.connect(server=GC.server, user=GC.user, password=GC.password, database=GC.database)32 cursor = conn.cursor()33 selectCobertura = f''' SELECT * FROM coberturas_mds_endosso where rs = {rs} '''34 cursor.execute(selectCobertura)35 listCoberturas = cursor.fetchall()36 conn.close()37 correctStatus = ['Ativo','Ativa','Emitido','Emitida']38 (39 seguradora40 ,tipoEndosso41 ,subtipoEndosso42 ,nuapolice43 ,nupropostacia44 ,segurado45 ,cpf_cnpj46 ,consultor47 ,datasolicitacao48 ,inicioVigencia49 ,fimVigencia50 ,email51 ,cep52 ,endereco53 ,cidade54 ,estado55 ,numero56 ,complemento57 ,ddd58 ,telefone59 ,dddc60 ,celular61 ,produto62 ,premioLiq63 ,adicional64 ,custo65 ,formarPgto66 ,qtdParcelas67 ,dataVencimento68 ,valorIOF69 ,premioTotal70 ,nupropostaquiver71 ,datacadastroquiver72 ,status73 ,statusRPA74 ,caminho_doc 75 ,Fabricante76 ,Modelo77 ,ano78 ,Placa79 ,Chassi80 ,FIPE81 ,CEPRISCO82 ,dataSubs83 ,classeBonus84 ,codCI85 ,categoria86 ,franquia_reduzida87 ,premio_liquido88 ,nomeCondutor89 ,cpfCondutor90 ,estadoCivilCondutor91 ,idadeCondutor92 ,detalhamento_franquia_vidro93 ,nota_fiscal94 ,nome_arq95 ,renavam96 ,genero97 ,cep_pernoite98 ,data_saida99 ,combustivel100 ) = db.initDB(rs)101 if classeBonus[0] == '0':102 classeBonus = classeBonus[1]103 insist = 5104 alerts = 5105 insisttext = 2106 defaultsleep = 2107 def AjusteCadastral(driver,wait):108 try:109 if 'cancelamento' in tipoEndosso.lower():110 return 1111 112 driver.switch_to.default_content()113 driver.switch_to.frame('ZonaInterna')114 driver.switch_to.frame('ZonaInterna')115 driver.switch_to.frame('Documento')116 driver.execute_script('abreCadastroCliente();')117 time.sleep(defaultsleep)118 driver.switch_to.default_content()119 driver.switch_to.frame('Cliente1')120 sleep(2)121 EF.fill(driver, '//*[@id="Cliente_EMail"]', email,insist)122 #Endereço123 sleep(2)124 EF.click(driver, '/html/body/form/div[7]/div/div[2]/div[6]/div[3]/div/div/div/div[1]/h2/label', insist)125 sleep(2)126 driver.switch_to.frame('FrameClienteEndereco1')127 campos_enderecos = driver.find_elements(By.XPATH,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr')128 129 #Faz a validação para trocar de paginas se ter muitos endereços130 validacao_endereco = False131 ValidacaoIncluir = False132 EscreverEndereco = False133 sleep(2)134 ultima_pag = driver.find_element_by_xpath('/html/body/form/div[3]/div/span[1]/span/div/div[5]/div/table/tbody/tr/td[2]/table/tbody/tr/td[4]/span').get_attribute("innerHTML")135 ultima_pag = int(ultima_pag)136 pag_atual = 1137 limite = 4138 sleep(1)139 #Validação que troca de pagina 140 while (pag_atual <= ultima_pag):141 if pag_atual <= ultima_pag and validacao_endereco == True:142 break143 while not validacao_endereco == True:144 for x in range(2,len(campos_enderecos)+1):145 #Pega os campos de endereço146 lista = []147 EnderecoValida =EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[3]'.format(x),insist,'innerText').lower()148 NumeroValida = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[4]'.format(x),insist,'innerText').lower()149 CepValida = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[5]'.format(x),insist,'innerText').lower()150 ComplementoValida = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[6]'.format(x),insist,'innerText').lower()151 CidadeValida = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[7]'.format(x),insist,'innerText').lower()152 EstadoValida = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[8]'.format(x),insist,'innerText').lower()153 lista.append(EnderecoValida)154 lista.append(NumeroValida)155 lista.append(CepValida)156 lista.append(ComplementoValida)157 lista.append(CidadeValida)158 lista.append(EstadoValida)159 #Retira os acentos160 try:161 EnderecoValida1 = unidecode(lista[0])162 except:163 pass164 try:165 CidadeValida1 = unidecode(lista[4])166 except:167 pass168 try:169 ComplementoValida1 = unidecode(lista[3])170 except:171 pass172 try:173 EstadoValida1 = unidecode(lista[5])174 except:175 pass176 177 #Faz a validação178 ValidacaoEndereco = EnderecoValida != endereco.lower() 179 ValidaEnderecoAcento = EnderecoValida1 == endereco.lower()180 ValidacaoNumero = NumeroValida != numero.lower()181 ValidacaoCep = CepValida != cep.lower()182 ValidacaoComplemento = ComplementoValida.strip() != complemento.lower()183 ValidaComplementoAcento = ComplementoValida1 == complemento.lower()184 ValidacaoCidade = CidadeValida != cidade.lower()185 ValidacaoEstado = EstadoValida != estado.lower()186 ValidacaoEstadoAcento = EstadoValida1 == estado.lower()187 if ValidacaoCidade == True:188 ValidaCidadeAcento = CidadeValida1 == cidade.lower()189 else:190 ValidaCidadeAcento = CidadeValida1 != cidade.lower()191 # if '0' in numero:192 # listanum = [numero]193 # ultimonum = [z in listanum for z]194 try:195 if ValidacaoEndereco and ValidacaoCep and ValidacaoComplemento:196 if ValidaEnderecoAcento:197 print('Deu Certo')198 validacao_endereco = True199 break200 else:201 print('Endereço diferente')202 x += 1203 continue204 elif ValidacaoNumero:205 print('Número diferente')206 x += 1207 continue208 elif ValidacaoCep:209 print('Cep diferente')210 x += 1211 continue212 elif ValidacaoComplemento and ValidacaoCep:213 if ValidaComplementoAcento:214 print('Deu Certo')215 validacao_endereco = True216 break217 else:218 print('Complemento Diferente')219 x += 1220 continue221 elif ValidacaoCidade:222 if ValidaCidadeAcento:223 print('Deu Certo')224 validacao_endereco = True225 break226 else:227 print('Cidade diferente')228 x += 1229 continue230 elif ValidacaoEstado:231 if ValidacaoEstadoAcento:232 print('Deu Certo')233 validacao_endereco = True234 break235 else:236 print('Estado diferente')237 x += 1238 continue239 else:240 print('Deu Certo')241 validacao_endereco = True242 break243 except:244 driver.switch_to.default_content()245 driver.switch_to.frame('Cliente1')246 driver.execute_script("incluirClienteEndereco1();")247 ValidacaoIncluir = False248 pass249 250 if ValidacaoIncluir == True and validacao_endereco == False:251 driver.switch_to.default_content()252 driver.switch_to.frame('Cliente1')253 driver.execute_script("incluirClienteEndereco1();")254 EscreverEndereco = True255 else:256 if validacao_endereco == False:257 if pag_atual == ultima_pag:258 driver.switch_to.default_content()259 driver.switch_to.frame('Cliente1')260 driver.execute_script("incluirClienteEndereco1();")261 EscreverEndereco = True262 else:263 pass264 265 if EscreverEndereco == True:266 driver.switch_to.frame('ZonaInterna')267 sleep(2)268 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[1]/div/input',cep,insist)269 sleep(2)270 driver.execute_script(f'document.getElementById("ClienteEnder_Endereco").value="{endereco}" ')271 sleep(1)272 driver.execute_script(f'document.getElementById("ClienteEnder_Numero").value="{numero}" ')273 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div/div[1]/div/input',complemento,insist)274 sleep(1)275 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div/div[3]/div/input',cidade,insist)276 sleep(1)277 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div/div[4]/div/input',estado,insist)278 sleep(1)279 driver.execute_script("if (!document.getElementById('table_Toolbar').disabled) { evento('Gravar'); }")280 sleep(1)281 driver.execute_script("if (!document.getElementById('table_Toolbar').disabled) { evento('Incluir'); }")282 sleep(1)283 driver.execute_script("if (!document.getElementById('table_Toolbar').disabled) { evento('Voltar'); }")284 sleep(1)285 driver.switch_to.default_content()286 alert = '/html/body/div[5]/div'287 sleep(2)288 try:289 if driver.find_elements(By.XPATH,alert):290 EF.click(driver,'/html/body/div[5]/div/div[3]/button[1]',insist)291 except:pass292 validacao_endereco = True293 sleep(1)294 if(pag_atual != ultima_pag):295 sleep(1)296 xpath = '//*[@id="next_BAR_GridCadastro2"]'297 btn_prox = EF.click(driver,xpath,insist)298 sleep(1)299 pag_atual += 1300 else:301 break 302 #Telefone303 sleep(1)304 driver.switch_to.default_content()305 driver.switch_to.frame('Cliente1')306 sleep(3)307 EF.click(driver, '//*[@id="icone-ClienteTelefone1"]', insist)308 sleep(2)309 driver.switch_to.frame('FrameClienteTelefone1')310 sleep(3)311 trTelefones = driver.find_elements(By.XPATH,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr')312 lenTelefone = len(trTelefones)+1313 listFindTelefone = []314 sleep(1)315 ultima_pag = driver.find_element_by_xpath('/html/body/form/div[3]/div/span[1]/span/div/div[5]/div/table/tbody/tr/td[2]/table/tbody/tr/td[4]/span').get_attribute("innerHTML")316 ultima_pag = int(ultima_pag)317 pag_atual = 1318 limite = 4319 while (pag_atual <= ultima_pag):320 for x in range(1,lenTelefone):321 numeroTelefone = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[3]'.format(x),insist,'innerText').lower()322 telefonevalida = numeroTelefone == telefone and numeroTelefone != '' or numeroTelefone == telefone.replace('-','') and numeroTelefone != ''323 telefonevazio = numeroTelefone == ''324 celularvalida = celular == numeroTelefone or celular.replace('-','') == numeroTelefone325 if telefonevalida or celularvalida:326 listFindTelefone.append(True)327 else:328 if telefonevazio:329 continue330 else:331 listFindTelefone.append(False)332 if(pag_atual != ultima_pag):333 xpath = '/html/body/form/div[3]/div/span[1]/span/div/div[5]/div/table/tbody/tr/td[2]/table/tbody/tr/td[6]'334 btn_prox = EF.click(driver,xpath,insist)335 sleep(1)336 pag_atual += 1337 else:338 break 339 if True not in listFindTelefone:340 print('fazer validação para inserir telefone')341 342 driver.switch_to.default_content()343 driver.switch_to.frame('Cliente1')344 driver.execute_script("incluirClienteTelefone1();")345 driver.switch_to.frame('ZonaInterna')346 if ddd == '':347 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div/div[1]/div/input',dddc,insist,1)348 else:349 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div/div[1]/div/input',ddd,insist,1)350 if telefone == '':351 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div/div[2]/div/input',celular,insist)352 else:353 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div/div[2]/div/input',telefone,insist)354 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div/div[4]/div/span/span[1]/span/span[1]',insist)355 EF.click(driver,'/html/body/span[2]/span/span[2]/ul/li[12]',insist)356 driver.switch_to.default_content()357 driver.switch_to.frame('Cliente1')358 driver.execute_script("evento('Gravar')")359 driver.switch_to.default_content()360 sleep(5)361 alert = '/html/body/div[3]/div'362 textoAlert = '/html/body/div[5]/div/div[2]'363 if driver.find_elements(By.XPATH,alert):364 try:365 textAlert = driver.find_element(By.XPATH,textoAlert).get_attribute('innerText').lower()366 if 'já possui uma proposta' in textAlert:367 # raise ValueError('Erro - endosso já possui proposta')368 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[1]',insist)369 370 elif 'nível corretora' in textAlert:371 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[1]',insist)372 EF.click(driver,'/html/body/div[5]/div/div[2]/div[1]/div/div/button[1]',insist)373 sleep(3)374 elif 'cadastro de clientes' in textAlert:375 pass376 else:377 EF.click(driver,'/html/body/div[5]/div/div[3]/button[1]',insist)378 except:379 pass380 driver.switch_to.frame('Cliente1')381 EF.click(driver,'//*[@id="Button1"]',insist)382 driver.switch_to.default_content()383 alertnovo = '/html/body/div[6]/div'384 alert = '/html/body/div[3]/div'385 if driver.find_elements(By.XPATH,alertnovo):386 EF.click(driver, '/html/body/div[6]/div/div[3]/button[1]', insist)387 if driver.find_elements(By.XPATH,alert):388 EF.click(driver, '/html/body/div[5]/div/div[3]/button[1]', insist)389 390 except ValueError as err:391 raise ValueError(err)392 except Exception as err:393 raise Exception('Erro - Inserir dados cadastrais')394 395 def CadastroCoberturas(driver,wait,rs):396 try:397 sleep(2)398 driver.switch_to.default_content()399 try:400 ExperienciaCliente = '/html/body/div[3]'401 if driver.find_element(By.XPATH,ExperienciaCliente):402 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)403 except:pass404 EF.acessarframe(driver, 'ZonaInterna',2)405 driver.switch_to.frame('Documento')406 driver.switch_to.frame('ZonaInterna')407 #Clica em coberturas408 driver.execute_script("expandirComprimeCard('BoxDocumentoItemVeiculoCob');openBoxDocumentoItemVeiculoCob();")409 driver.switch_to.default_content()410 try:411 ExperienciaCliente = '/html/body/div[3]'412 if driver.find_element(By.XPATH,ExperienciaCliente):413 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)414 except:pass415 EF.acessarframe(driver, 'ZonaInterna',2)416 driver.switch_to.frame('Documento')417 driver.switch_to.frame('ZonaInterna')418 sleep(2)419 driver.switch_to.frame('FrameDocumentoItemVeiculoCob')420 421 Findelements = 0422 while Findelements == 0:423 driver.switch_to.default_content()424 try:425 ExperienciaCliente = '/html/body/div[3]'426 if driver.find_element(By.XPATH,ExperienciaCliente):427 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)428 except:pass429 EF.acessarframe(driver, 'ZonaInterna',2)430 driver.switch_to.frame('Documento')431 driver.switch_to.frame('ZonaInterna')432 driver.switch_to.frame('FrameDocumentoItemVeiculoCob')433 elemBtnExluir = driver.find_elements(By.ID,'BtExcluir')434 if len(elemBtnExluir) != 0:435 sleep(1)436 try:437 elemBtnExluir[0].click()438 except:439 driver.switch_to.default_content()440 try:441 ExperienciaCliente = '/html/body/div[3]'442 if driver.find_element(By.XPATH,ExperienciaCliente):443 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)444 except:pass445 EF.acessarframe(driver, 'ZonaInterna',2)446 driver.switch_to.frame('Documento')447 driver.switch_to.frame('ZonaInterna')448 driver.switch_to.frame('FrameDocumentoItemVeiculoCob')449 if len(elemBtnExluir) != 0:450 sleep(1)451 elemBtnExluir[0].click()452 else:453 Findelements = 1454 else:455 Findelements = 1456 driver.switch_to.default_content()457 alertnovo = '/html/body/div[4]/div'458 alert = '/html/body/div[3]/div'459 try:460 ExperienciaCliente = '/html/body/div[3]'461 if driver.find_element(By.XPATH,ExperienciaCliente):462 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)463 except:pass464 try:465 if driver.find_elements(By.XPATH,alert):466 EF.click(driver, '/html/body/div[3]/div/div[3]/button[1]', insist)467 if driver.find_elements(By.XPATH,alertnovo):468 EF.click(driver,'/html/body/div[4]/div/div[3]/button[1]',insist)469 except:pass470 471 EF.acessarframe(driver, 'ZonaInterna',2)472 driver.switch_to.frame('Documento')473 driver.switch_to.frame('ZonaInterna')474 sleep(3)475 driver.switch_to.frame('FrameDocumentoItemVeiculoCob')476 sleep(2)477 driver.switch_to.default_content()478 EF.acessarframe(driver, 'ZonaInterna',2)479 driver.switch_to.frame('Documento')480 driver.switch_to.frame('ZonaInterna')481 482 #Clica em incluir coberturas483 driver.execute_script("incluirDocumentoItemVeiculoCob();")484 sleep(2)485 driver.switch_to.default_content()486 EF.acessarframe(driver, 'ZonaInterna',2)487 driver.switch_to.frame('Documento')488 driver.switch_to.frame('ZonaInterna')489 driver.switch_to.frame('ZonaInterna')490 chave = False491 for x in listCoberturas:492 nomeCobertura = x[2]493 valor_ajuste_Cobertura = x[3].replace('r$','').replace('*','').strip()494 if 'franquia' in nomeCobertura and 'casco' in nomeCobertura:495 nomeCoberturasplit = nomeCobertura.split(' ')496 nomeCobertura = nomeCoberturasplit[1]497 findCobertura = 0498 if chave == False:499 wait.until(EC.visibility_of_element_located((By.ID,'select2-DocumentoIteCob_Cobertura-container'))).click()500 # driver.find_element(By.ID,'select2-DocumentoIteCob_Cobertura-container').click()501 EF.fill(driver,'/html/body/span[2]/span/span[1]/input',nomeCobertura,insist,1)502 sleep(1)503 listItens = driver.find_elements(By.XPATH,'/html/body/span[2]/span/span[2]/ul/li')504 for item in listItens:505 itemValue = item.get_attribute('innerText')506 #print(itemValue)507 if itemValue.lower() == nomeCobertura and valor_ajuste_Cobertura != '0,00' and valor_ajuste_Cobertura != '0,0':508 item.click()509 findCobertura = 1510 chave = False511 break512 else:513 driver.find_element(By.XPATH,'/html/body/span[2]/span/span[1]/input').clear()514 chave = True515 if 'Nenhum resultado encontrado' in itemValue:516 conn = pymssql.connect(server=GC.server, user=GC.user, password=GC.password, database=GC.database)517 cursor = conn.cursor()518 data_atual = date.today()519 path_to_save = f'Evidencia-{rs}-Endosso-Erro-Cobertura-{data_atual}.png'520 driver.save_screenshot(GC.evidencia_path + path_to_save)521 insert = f'''522 insert into coberturas_erro_log(523 rs524 ,erro_name525 ,erro_path526 )VALUES(527 {rs}528 ,'Incluir cobertura'529 ,'{path_to_save}'530 )531 '''532 cursor.execute(insert)533 conn.commit()534 conn.close()535 if findCobertura != 0: 536 sleep(3)537 if 'casco' not in nomeCobertura.lower():538 #Insere valor da cobertura539 if ',' in valor_ajuste_Cobertura:540 driver.execute_script(f"document.getElementById('DocumentoIteCob_ImpSegurada').setAttribute('value', '{valor_ajuste_Cobertura}')")541 else:542 driver.execute_script(f"document.getElementById('DocumentoIteCob_ImpSegurada').setAttribute('value', '0,0')")543 sleep(3)544 if 'vidro' in nomeCobertura.lower():545 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[3]/div/div/textarea',detalhamento_franquia_vidro,insist)546 else:547 #Insere ajuste548 if seguradora.lower() == 'porto seguro cia' or seguradora.lower() == 'porto':549 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[1]/div/div/input',insist)550 sleep(3)551 # #tipo de franquia552 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[2]/div[1]/div/span/span[1]/span/span[1]',insist)553 selectable = driver.find_elements(By.XPATH,'/html/body/span[2]/span/span[2]/ul/li')554 for i in range(0,len(selectable)):555 option1 = EF.getText(driver,f'/html/body/span[2]/span/span[2]/ul/li[{i}]',insist,'innerText')556 557 option1 = option1.split(' ')558 option1 = option1[0]559 if option1.lower() == 'obrigatoria':560 option1 = 'obrigatória'561 if option1.lower() == franquia_reduzida.lower():562 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[2]/div[2]/div/input',insist)563 selectTipoFranquia = Select(driver.find_element(By.ID,'DocumentoIteCob_TipoFranquia'))564 i = i-1565 selectTipoFranquia.select_by_index(i)566 break567 sleep(3)568 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[2]/div[2]/div/input',valor_ajuste_Cobertura,insist,1)569 else:570 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/input',valor_ajuste_Cobertura,insist,1)571 sleep(3)572 #Seleciona 'tem franquia'573 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[1]/div/div/input',insist)574 sleep(3)575 #tipo de franquia576 selectTipoFranquia = Select(driver.find_element(By.ID,'DocumentoIteCob_TipoFranquia'))577 try:578 if '50' in franquia_reduzida:579 selectTipoFranquia.select_by_index(27)580 elif '75' in franquia_reduzida:581 selectTipoFranquia.select_by_index(23)582 elif '25' in franquia_reduzida:583 selectTipoFranquia.select_by_index(34)584 except:pass585 sleep(3)586 #Insere valor da franquia587 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div[2]/div[2]/div[2]/div/input',franquia_reduzida,insist,1)588 sleep(3)589 driver.execute_script("evento('Gravar')")590 driver.execute_script("evento('Incluir')")591 592 driver.execute_script("evento('Voltar')")593 driver.switch_to.default_content()594 sleep(3)595 try:596 try:597 if driver.find_element(By.XPATH,'/html/body/div[4]/div'):598 EF.click(driver,'/html/body/div[4]/div/div[3]/button[1]',insist)599 except:pass600 if driver.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/button[1]'):601 EF.click(driver,'/html/body/div[3]/div/div[3]/button[1]',insist)602 except:pass603 except ValueError as err:604 raise ValueError(err)605 except Exception as err:606 raise Exception('Erro - Incluir cobertura')607 def CadastroCondutor(driver,wait,rs):608 try: 609 driver.switch_to.default_content()610 EF.acessarframe(driver, 'ZonaInterna',2)611 driver.switch_to.frame('Documento')612 driver.switch_to.frame('ZonaInterna')613 #clica em condutores614 sleep(2)615 driver.execute_script("expandirComprimeCard('BoxDocsItensAutoCond');openBoxDocsItensAutoCond();")616 617 driver.switch_to.frame('FrameDocsItensAutoCond')618 sleep(2)619 #clica em editar condutor620 if '0km' in Modelo.lower():621 driver.switch_to.default_content()622 driver.switch_to.frame('ZonaInterna')623 driver.switch_to.frame('ZonaInterna')624 driver.switch_to.frame('Documento')625 driver.switch_to.frame('ZonaInterna')626 driver.execute_script("incluirDocsItensAutoCond();")627 sleep(2)628 if segurado.lower() == nomeCondutor.lower():629 driver.switch_to.default_content()630 EF.click(driver,'/html/body/div[4]/div/div[2]/div[1]/div/div/button[1]',insist)631 try:632 ExperienciaCliente = '/html/body/div[3]'633 if driver.find_element(By.XPATH,ExperienciaCliente):634 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)635 except:pass636 chave = False637 try:638 if driver.find_elements(By.XPATH,'/html/body/div[3]/div'):639 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[1]', insist)640 chave = True641 except:pass642 driver.switch_to.frame('ZonaInterna')643 driver.switch_to.frame('ZonaInterna')644 driver.switch_to.frame('Documento')645 driver.switch_to.frame('ZonaInterna')646 driver.switch_to.frame('ZonaInterna')647 if chave ==False:648 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div[2]/div/div/input',insist)649 casado = 'casado' in estadoCivilCondutor.lower()650 solteiro = 'solteiro' in estadoCivilCondutor.lower()651 viuvo = 'viúvo' in estadoCivilCondutor.lower()652 desquitado = 'desquitado' in estadoCivilCondutor.lower()653 divorciado = 'divorciado' in estadoCivilCondutor.lower()654 sleep(2)655 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[2]', insist)656 sleep(1)657 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div[1]/div/input',nomeCondutor,insist,1)658 elem = driver.find_element(By.NAME,"DocumentoIteCond_Idade")659 elem.send_keys(idadeCondutor)660 sleep(2)661 if casado:662 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[1]/input',insist)663 elif solteiro:664 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[2]/input',insist)665 elif viuvo:666 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[3]/input',insist)667 elif desquitado:668 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[4]/input',insist)669 elif divorciado:670 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[5]/input',insist)671 else:672 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[6]/input',insist)673 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/input',cpfCondutor,insist)674 if nomeCondutor.lower() != segurado.lower():675 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[4]/div[1]/div/input', 'Não Informado', insist, 1)676 elif nomeCondutor.lower() == segurado.lower():677 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[4]/div[1]/div/input', 'O Próprio', insist, 1)678 679 sleep(2)680 681 #diz o genero do condutor682 if 'masculino' in genero:683 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/div/label[1]/input',insist)684 elif 'feminino' in genero:685 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/div/label[2]/input',insist)686 else:687 driver.switch_to.default_content()688 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[2]',insist)689 try:690 ExperienciaCliente = '/html/body/div[3]'691 if driver.find_element(By.XPATH,ExperienciaCliente):692 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)693 except:pass694 sleep(1)695 EF.acessarframe(driver, 'ZonaInterna',2)696 driver.switch_to.frame('Documento')697 driver.switch_to.frame('ZonaInterna')698 driver.switch_to.frame('ZonaInterna')699 sleep(2)700 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div[2]/div/div/input',insist)701 702 casado = 'casado' in estadoCivilCondutor.lower()703 solteiro = 'solteiro' in estadoCivilCondutor.lower()704 viuvo = 'viúvo' in estadoCivilCondutor.lower()705 desquitado = 'desquitado' in estadoCivilCondutor.lower()706 divorciado = 'divorciado' in estadoCivilCondutor.lower()707 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[2]', insist)708 sleep(1)709 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div[1]/div/input',nomeCondutor,insist,1)710 elem = driver.find_element(By.NAME,"DocumentoIteCond_Idade")711 elem.send_keys(idadeCondutor)712 if casado:713 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[1]/input',insist)714 elif solteiro:715 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[2]/input',insist)716 elif viuvo:717 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[3]/input',insist)718 elif desquitado:719 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[4]/input',insist)720 elif divorciado:721 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[5]/input',insist)722 else:723 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[6]/input',insist)724 sleep(2)725 if nomeCondutor.lower() != segurado.lower():726 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[4]/div[1]/div/input', 'Não Informado', insist, 1)727 elif nomeCondutor.lower() == segurado.lower():728 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[4]/div[1]/div/input', 'O Próprio', insist, 1)729 #diz o genero do condutor730 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/input',cpfCondutor,insist)731 if 'masculino' in genero:732 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/div/label[1]/input',insist)733 elif 'feminino' in genero:734 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/div/label[2]/input',insist)735 sleep(2)736 737 else:738 verificatexto = EF.getText(driver,'/html/body/form/div[3]/div/span[1]/span/div/div[5]/div/table/tbody/tr/td[1]/div')739 if verificatexto == 'Nenhum registro':740 driver.switch_to.default_content()741 driver.switch_to.frame('ZonaInterna')742 driver.switch_to.frame('ZonaInterna')743 driver.switch_to.frame('Documento')744 driver.switch_to.frame('ZonaInterna')745 driver.execute_script("incluirDocsItensAutoCond();")746 if segurado.lower() == nomeCondutor.lower():747 driver.switch_to.default_content()748 EF.click(driver,'/html/body/div[4]/div/div[2]/div[1]/div/div/button[1]',insist)749 else:750 driver.switch_to.default_content()751 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[2]',insist)752 else:753 sleep(5)754 editar = driver.find_element(By.XPATH,'/html/body/form/div[3]/div/span[1]/span/div/div[3]/div[3]/div/table/tbody/tr[2]/td[1]/a')755 driver.execute_script("arguments[0].click();", editar)756 sleep(2)757 driver.switch_to.default_content()758 EF.acessarframe(driver, 'ZonaInterna',2)759 driver.switch_to.frame('Documento')760 driver.switch_to.frame('ZonaInterna')761 driver.switch_to.frame('ZonaInterna')762 sleep(2)763 wait.until(EC.visibility_of_element_located((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div')))764 sleep(2)765 #Nome Condutor766 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[1]/div[2]/div/div/input',insist)767 sleep(2)768 driver.execute_script(f"document.getElementById('DocumentoIteCond_Nome').setAttribute('value', '{nomeCondutor}')")769 770 #Idade771 sleep(2)772 773 EF.click(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[2]/div/input', insist)774 sleep(2)775 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[2]/div/input', idadeCondutor, insist, 1)776 sleep(2)777 #Estado Civil778 allEstadoCivil = driver.find_elements(By.XPATH, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label')779 lenEstadoCivil = len(allEstadoCivil)+1780 for x in range(1,lenEstadoCivil):781 valueOption = EF.getText(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[{}]/label'.format(x),insist,'innerText')782 if valueOption.lower() in estadoCivilCondutor:783 sleep(2)784 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[4]/div/div/label[{}]/input'.format(x), insist)785 break786 #Cpf787 sleep(2)788 driver.execute_script(f"document.getElementById('DocumentoIteCond_CnpjCpf').setAttribute('value', '{cpfCondutor}')")789 sleep(3)790 #Parentesco ou relacionamento com o condutor principal791 if nomeCondutor.lower() != segurado.lower():792 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[4]/div[1]/div/input', 'Não Informado', insist, 1)793 elif nomeCondutor.lower() == segurado.lower():794 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[4]/div[1]/div/input', 'O Próprio', insist, 1)795 #diz o genero do condutor796 sleep(2)797 if 'masculino' in genero.lower():798 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/div/label[1]/input',insist)799 elif 'feminino' in genero.lower():800 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div/div[2]/div[2]/div[3]/div/div/label[2]/input',insist)801 #Clica em gravar802 sleep(2)803 driver.execute_script("evento('Gravar')")804 sleep(3)805 driver.execute_script("evento('Incluir')")806 driver.execute_script("evento('Voltar')")807 driver.switch_to.default_content()808 809 alert = '/html/body/div[3]/div'810 alertnovo = '/html/body/div[4]/div'811 sleep(3)812 try:813 if driver.find_elements(By.XPATH,alertnovo):814 EF.click(driver,'/html/body/div[4]/div/div[3]/button[1]',insist)815 if driver.find_elements(By.XPATH,alert):816 EF.click(driver, '/html/body/div[3]/div/div[3]/button[1]', insist)817 except:pass818 except ValueError as err:819 raise ValueError(err)820 except Exception as err:821 raise Exception('Erro - Incluir condutor')822 def CadastroProduto(driver,wait,rs):823 try:824 if 'cancalemento' in tipoEndosso.lower():825 return 1826 if 'itens' not in subtipoEndosso.lower():827 return 1828 sleep(2)829 driver.execute_script('incluirDocumentoItemVeiculo();')830 driver.switch_to.default_content()831 alertnovo = '/html/body/div[4]/div'832 try:833 if driver.find_elements(By.XPATH,alertnovo):834 EF.click(driver,'/html/body/div[4]/div/div[3]/button[1]',insist)835 except:pass836 try:837 ExperienciaCliente = '/html/body/div[3]'838 if driver.find_element(By.XPATH,ExperienciaCliente):839 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)840 except:pass841 EF.acessarframe(driver, 'ZonaInterna',2)842 driver.switch_to.frame('Documento')843 driver.switch_to.frame('ZonaInterna')844 sleep(2) 845 EF.click(driver, '//*[@id="TEMIMPORTA"]', insist)846 sleep(5)847 try:848 obj = driver.find_element_by_xpath('/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[1]/div/div/span/div[1]/div[3]/div[3]/div/table/tbody/tr[2]')849 actions = ActionChains(driver)850 actions.double_click(obj).perform()851 except:852 pass853 ##Desmarcar 0km enquanto não temos numero da nota fiscal854 sleep(3)855 ValidarVeiculo = False856 try:857 if driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[3]/div[2]/div/input').is_selected():858 EF.click(driver, '//*[@id="DocumentoIte_ZeroKm"]', insist)859 ValidarVeiculo = True860 if '0km' in Modelo.lower():861 sleep(2)862 EF.click(driver, '//*[@id="DocumentoIte_ZeroKm"]', insist)863 ValidarVeiculo = True864 except:865 if ValidarVeiculo == False:866 if '0km' in Modelo.lower():867 sleep(2)868 EF.click(driver, '//*[@id="DocumentoIte_ZeroKm"]', insist)869 ValidarVeiculo = True870 pass871 #Fabricante872 EF.click(driver, '//*[@id="select2-DocumentoIte_Fabricante-container"]', insist)873 sleep(2)874 EF.fill(driver, '/html/body/span[2]/span/span[1]/input',Fabricante,insist)875 sleep(2)876 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li', insist)877 #Modelo878 sleep(2)879 EF.click(driver, '//*[@id="DocumentoIte_DescrModelo"]', insist)880 sleep(2)881 EF.fill(driver, '//*[@id="DocumentoIte_DescrModelo"]',Modelo,insist)882 sleep(1)883 884 flex = 'flex' in Modelo.lower()885 gasolina = combustivel.lower()== 'gasolina'886 diesel = combustivel.lower() == 'diesel' 887 alcool = combustivel.lower() == 'álcool'888 eletrico = combustivel.lower() == 'elétrico' 889 tetrafuel = combustivel.lower() == 'tetrafuel' 890 gas = combustivel.lower() == 'gas' 891 sleep(2)892 if '0km' in Modelo.lower():893 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[4]/div[6]/div/input',nota_fiscal,insist)894 if flex:895 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[5]/input'))))896 elif gasolina:897 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[1]/input'))))898 elif diesel:899 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[3]/input'))))900 elif alcool:901 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[2]/input'))))902 elif eletrico:903 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[10]/input'))))904 elif tetrafuel:905 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[11]/input'))))906 elif gas:907 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[4]/input'))))908 else:909 driver.execute_script("arguments[0].click();",wait.until(EC.element_to_be_clickable((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[6]/div/div/label[1]/input'))))910 sleep(1)911 try:912 anoFab, anoMod = ano.split(',')913 except:914 anoFab, anoMod = ano.split('/')915 validacaoanofab = driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input')916 validacaoanofab1 = validacaoanofab.get_attribute('value')917 sleep(2)918 driver.execute_script(f"document.getElementById('DocumentoIte_AnoFabricacao').setAttribute('value', '{anoFab}')")919 validacaoanofab2 = driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input')920 validacaoanofab3 = validacaoanofab2.get_attribute('value')921 922 if validacaoanofab1 == validacaoanofab3 and anoFab != anoMod or validacaoanofab3 != anoFab:923 try:924 driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input').clear()925 sleep(2)926 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input',anoFab,insist)927 sleep(2)928 except:929 driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input').clear()930 sleep(2)931 driver.execute_script(f'document.getElementById("DocumentoIte_AnoFabricacao").value="{anoFab}" ')932 sleep(3)933 validacaoanofab4 = driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input')934 validacaoanofab5 = validacaoanofab4.get_attribute('value')935 if validacaoanofab5 == '0':936 driver.find_element(By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input').clear()937 EF.fill(driver,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[3]/div[4]/div/input',anoFab,insist)938 sleep(2)939 EF.click(driver, '//*[@id="DocumentoIte_AnoModelo"]', insist)940 time.sleep(defaultsleep)941 EF.fill(driver, '//*[@id="DocumentoIte_AnoModelo"]',anoMod, insist,1)942 sleep(2)943 EF.fill(driver, '//*[@id="DocumentoIte_Placa"]',Placa, insist)944 sleep(2)945 EF.fill(driver, '//*[@id="DocumentoIte_Chassi"]',Chassi, insist)946 sleep(2) 947 driver.find_element(By.XPATH,'//*[@id="DocumentoIte_Renavam"]').clear()948 sleep(1)949 if seguradora == 'Allianz':950 driver.find_element(By.XPATH,'//*[@id="DocumentoIte_Renavam"]').clear()951 else:952 if renavam != '':953 driver.find_element(By.XPATH,'//*[@id="DocumentoIte_Renavam"]').clear()954 sleep(2)955 driver.find_element(By.XPATH,'//*[@id="DocumentoIte_Renavam"]').send_keys(renavam)956 EF.fill(driver, '//*[@id="DocumentoIte_CodFipe"]',FIPE, insist)957 sleep(2)958 sleep(1)959 if '0km' in Modelo.lower():960 EF.fill(driver,'//*[@id="DocumentoIte_DataSaida"]',data_saida,insist)961 if seguradora == 'Allianz':962 EF.fill(driver, '//*[@id="DocumentoIte_NotaFiscal"]', 'A/C', insist)963 #Categoria964 EF.click(driver, '/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[5]/div[5]/div/span', insist)965 966 EF.fill(driver, '/html/body/span[2]/span/span[1]/input', categoria,insist)967 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li', insist)968 EF.fill(driver, '//*[@id="DocumentoIte_Cep"]',CEPRISCO, insist)969 970 #Cidade971 driver.execute_script("acionaJanelaDocumentoIte_AuxCodCidade();")972 sleep(5)973 driver.switch_to.frame('SearchCidades3')974 975 chavelidacao = False976 chave = False977 wait.until(EC.visibility_of_element_located((By.XPATH,'//*[@id="Nome"]'))).send_keys(cidade)978 sleep(1)979 EF.click(driver, '//*[@id="SpanToolBarRightB"]/button', insist)980 sleep(1)981 alertnovo = '/html/body/div[4]/div'982 alert = '/html/body/div[3]/div'983 try:984 driver.switch_to.default_content()985 if driver.find_element(By.XPATH,'/html/body/div[3]/div'):986 sleep(1)987 try:988 driver.find_element(By.XPATH,'/html/body/div[3]/div/div[3]/button[1]').click()989 chave = True990 sleep(2)991 EF.acessarframe(driver, 'ZonaInterna',2)992 driver.switch_to.frame('Documento')993 driver.switch_to.frame('ZonaInterna')994 EF.click(driver,'/html/body/form/div[11]/div/div/div[1]/button/span',insist)995 chavelidacao = True996 except:997 if driver.find_element(By.XPATH,'/html/body/div[4]/div'):998 sleep(1)999 driver.find_element(By.XPATH,'/html/body/div[4]/div/div[3]/button[1]').click()1000 chave = True1001 sleep(2)1002 EF.acessarframe(driver, 'ZonaInterna',2)1003 driver.switch_to.frame('Documento')1004 driver.switch_to.frame('ZonaInterna')1005 EF.click(driver,'/html/body/form/div[11]/div/div/div[1]/button/span',insist)1006 chavelidacao = True1007 except:pass1008 if chave == False:1009 EF.acessarframe(driver, 'ZonaInterna',2)1010 driver.switch_to.frame('Documento')1011 driver.switch_to.frame('ZonaInterna')1012 driver.switch_to.frame('SearchCidades3')1013 if chavelidacao == False:1014 xpathTr = '/html/body/form/div[5]/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr'1015 wait.until(EC.visibility_of_element_located((By.XPATH,'/html/body/form/div[5]/div[2]/div[2]/div/div[3]/div[3]/div/table')))1016 teste = driver.find_elements(By.XPATH,xpathTr)1017 lenTeste = len(teste)+11018 for x in range(1,lenTeste):1019 estadoRegistro = driver.find_element(By.XPATH,'/html/body/form/div[5]/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[2]'.format(x)).get_attribute('innerText').lower()1020 if estadoRegistro == estado.lower():1021 EF.click(driver,'/html/body/form/div[5]/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[{}]/td[1]/a'.format(x),insist)1022 break1023 driver.switch_to.default_content()1024 EF.acessarframe(driver, 'ZonaInterna',2)1025 driver.switch_to.frame('Documento')1026 driver.switch_to.frame('ZonaInterna')1027 sleep(4)1028 driver.execute_script(f'document.getElementById("DocumentoIte_Cep").value="{cep_pernoite}" ')1029 #Classe1030 1031 if 'classe' in classeBonus:1032 classe = classeBonus1033 else:1034 classe = 'classe {}'.format(classeBonus)1035 wait.until(EC.visibility_of_element_located((By.XPATH,'/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[7]/div[3]')))1036 EF.click(driver, '/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[7]/div[3]/div/span/span[1]/span/span[1]', insist)1037 EF.fill(driver, '/html/body/span[2]/span/span[1]/input', classe, insist)1038 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li[1]', insist)1039 #Cód. identificação1040 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[8]/div[5]/div/input', codCI, insist,1)1041 #Data substituição 1042 dataSubs = inicioVigencia1043 EF.click(driver, '/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[10]/div[3]/div/div/input', insist)1044 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div/div/div[2]/div/div[10]/div[3]/div/div/input', dataSubs, insist, 1)1045 sleep(3)1046 #Clica em gravar1047 sleep(2)1048 driver.execute_script("evento('Gravar')")1049 sleep(3)1050 CadastroCoberturas(driver,wait,rs)1051 CadastroCondutor(driver,wait,rs)1052 driver.switch_to.default_content()1053 try:1054 ExperienciaCliente = '/html/body/div[3]'1055 if driver.find_element(By.XPATH,ExperienciaCliente):1056 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)1057 except:pass1058 driver.switch_to.frame('ZonaInterna')1059 driver.switch_to.frame('ZonaInterna')1060 driver.switch_to.frame('Documento')1061 driver.switch_to.frame('ZonaInterna')1062 sleep(2)1063 driver.execute_script("evento('Incluir')")1064 driver.execute_script("evento('Voltar')")1065 driver.switch_to.default_content()1066 alert = '/html/body/div[3]/div'1067 alertnovo = '/html/body/div[4]/div'1068 sleep(3)1069 try:1070 try:1071 if driver.find_elements(By.XPATH,alertnovo):1072 EF.click(driver,'/html/body/div[4]/div/div[3]/button[1]',insist)1073 except:pass1074 if driver.find_elements(By.XPATH,alert):1075 EF.click(driver, '/html/body/div[3]/div/div[3]/button[1]', insist)1076 except:pass1077 driver.switch_to.frame('ZonaInterna')1078 driver.switch_to.frame('ZonaInterna')1079 driver.switch_to.frame('Documento')1080 pass1081 return chave1082 except ValueError as err:1083 raise ValueError(err)1084 1085 except Exception as err:1086 raise Exception('Erro - Substituir Veiculo')1087 def cadastraConsultor(driver):1088 driver.switch_to.default_content() 1089 driver.switch_to.frame('ZonaInterna')1090 driver.switch_to.frame('ZonaInterna')1091 driver.switch_to.frame('Documento')1092 driver.execute_script('AbreProdutores();')1093 driver.switch_to.default_content()1094 driver.switch_to.frame('DocumentoRepasse')1095 ############### Início do script do LIRA ###################1096 ultima_pag = driver.find_element_by_xpath('//*[@id="sp_1_BAR_GridCadastro2"]').get_attribute("innerHTML")1097 ultima_pag = int(ultima_pag)1098 pag_atual = 11099 limite = 41100 sleep(2)1101 while (pag_atual <= ultima_pag):1102 for x in range(2, 6):1103 try:1104 sleep(2)1105 td_consultor = driver.find_element_by_xpath(f'/html/body/form/div[3]/div/span[2]/span/div/div[3]/div[3]/div/table/tbody/tr[{x}]/td[1]')1106 td_consultor = td_consultor.get_attribute("innerHTML")1107 1108 if(td_consultor == 'CONSULTOR'):1109 sleep(2)1110 xpath = f'/html/body/form/div[3]/div/span[2]/span/div/div[3]/div[3]/div/table/tbody/tr[{x}]/td[4]/a'1111 btn_excluir = EF.click(driver,xpath,insist)1112 sleep(2)1113 driver.switch_to.default_content()1114 alertnovo = '/html/body/div[6]/div'1115 alertantigo = '/html/body/div[5]/div'1116 try:1117 if driver.find_elements(By.XPATH,alertnovo):1118 EF.click(driver,'/html/body/div[6]/div/div[3]/button[1]',insist)1119 except:pass1120 try:1121 if driver.find_elements(By.XPATH,alertantigo):1122 EF.click(driver,'/html/body/div[5]/div/div[3]/button[1]',insist)1123 except:pass1124 try:1125 xpath = 'body > div.swal2-container.swal2-center.swal2-fade.swal2-shown'1126 alerta_registro = driver.find_element_by_css_selector(xpath)1127 sleep(2)1128 except:1129 pass1130 1131 if(alerta_registro != ''):1132 #print('apareceu')1133 sleep(2)1134 xpath = '/html/body/div[5]/div/div[3]/button[1]'1135 btn_fechar = EF.click(driver,xpath,insist)1136 sleep(2)1137 1138 driver.switch_to.frame('DocumentoRepasse')1139 break1140 except:1141 pass1142 1143 if(pag_atual != ultima_pag):1144 xpath = '//*[@id="next_BAR_GridCadastro2"]'1145 btn_prox = EF.click(driver,xpath,insist)1146 sleep(1)1147 pag_atual += 11148 else:1149 break 1150 #Incluir Consultor1151 driver.switch_to.default_content()1152 driver.switch_to.frame('DocumentoRepasse')1153 driver.execute_script("eventoAjax('Incluir');")1154 driver.execute_script('acionaJanelaNivel1();')1155 driver.switch_to.frame('SearchNivelHierarq')1156 ############### Fim do script do LIRA ###################1157 EF.fill(driver, '//*[@id="Descricao"]', 'CONSULTOR', insist)1158 sleep(2)1159 driver.execute_script("eventoAjax('EXECUTA');")1160 try:1161 Alert(driver).accept()1162 except:pass1163 driver.execute_script('RowDblClick("11");')1164 sleep(2)1165 driver.switch_to.default_content()1166 driver.switch_to.frame('DocumentoRepasse')1167 sleep(2)1168 # Segunda parte1169 sleep(2)1170 btnPesquisaLupa = driver.find_element_by_xpath('//*[@id="Divisao1_Bt"]')1171 driver.execute_script("arguments[0].click();", btnPesquisaLupa)1172 sleep(2)1173 driver.switch_to.frame('SearchDivisao')1174 sleep(2)1175 EF.fill(driver, '//*[@id="Nome"]', consultor, insist)1176 sleep(2)1177 xpath = '//*[@id="Nome"]'1178 EF.click(driver, '//*[@id="SpanToolBarRightB"]/button')1179 sleep(2)1180 # Click no nome do consultor 1181 sleep(2)1182 EF.click(driver, '/html/body/form/div[5]/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td[1]/a/span', insist)1183 sleep(2)1184 EF.click(driver, '//*[@id="BtEdiReg"]', insist)1185 driver.switch_to.default_content()1186 driver.switch_to.frame('DocumentoRepasse')1187 EF.click(driver, '//*[@id="BtGravar"]', insist)1188 sleep(3)1189 driver.execute_script("evento('Voltar')")1190 sleep(3)1191 driver.switch_to.default_content()1192 sleep(3)1193 if driver.find_elements(By.XPATH,'/html/body/div[3]/div/div[3]/button[1]'):1194 EF.click(driver,'/html/body/div[3]/div/div[3]/button[1]',insist)1195 def importarquivos(driver):1196 EF.acessarframe(driver, 'ZonaInterna',2)1197 driver.switch_to.frame('Documento')1198 EF.click(driver,'/html/body/form/div[7]/div/div[1]/ul/li[2]/div[2]/div[1]',insist)1199 driver.switch_to.default_content()1200 time.sleep(defaultsleep)1201 driver.switch_to.frame('ScanImagem')1202 EF.fill(driver, '//*[@id="ScanImagem_Descricao"]', 'Proposta de Endosso', insist)1203 EF.click(driver, '//*[@id="select2-ScanImagem_TipoImagem-container"]', insist)1204 EF.fill(driver, '/html/body/span[2]/span/span[1]/input', 'apolice', insist)1205 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li[1]', insist)1206 driver.execute_script("AbrirJanelaMultiplosArquivos();")1207 driver.switch_to.frame('ScanImagem')1208 filepath = driver.find_element(By.ID,'files')1209 caminho_doc = GC.caminho_pdf + nome_arq1210 1211 filepath.send_keys(caminho_doc) 1212 EF.click(driver,'/html/body/form/div[2]/input',insist)1213 driver.switch_to.default_content()1214 driver.switch_to.frame('ScanImagem')1215 1216 #Clica em grava1217 EF.gravar(driver, '/html/body/div[5]/div/div[3]/button[1]', insist)1218 EF.click(driver, '//*[@id="BtGravar"]', insist)1219 EF.gravar(driver, '//*[@id="BtVoltar"]', insist)1220 1221 def preenchepremio(driver):1222 try:1223 #Verifica qual subtipo do endosso1224 if 'endosso sem movimento de prêmio' in tipoEndosso.lower():1225 return 11226 try:1227 ExperienciaCliente = '/html/body/div[3]'1228 if driver.find_element(By.XPATH,ExperienciaCliente):1229 EF.click(driver,'/html/body/div[3]/div[1]/a/span',insist)1230 except:pass1231 EF.acessarframe(driver, 'ZonaInterna',2)1232 driver.switch_to.frame('Documento')1233 1234 EF.click(driver, '//*[@id="TitPremios"]', insist)1235 if 'endosso cancelamento sem restituição' in tipoEndosso.lower():1236 EF.fill(driver, '//*[@id="Documento_PremioLiquido"]', '0,00',insist,0)1237 EF.gravar(driver, '//*[@id="BtGravar"]', insist)1238 return 11239 1240 EF.click(driver, '//*[@id="select2-Documento_MeioPagto-container"]', insist)1241 #Faz a validação do tipo de pagamento do Endosso1242 #pagamento em débito1243 if 'débito' in formarPgto: 1244 PagamentoDebito = 'DEBITO EM CONTA'1245 EF.fill(driver, '/html/body/span[2]/span/span[1]/input', PagamentoDebito.lower(),insist)1246 #pagamento em boleto/Ficha1247 elif 'boleto' in formarPgto and not 'débito' in formarPgto or 'ficha' in formarPgto:1248 PagamentoBoleto = 'BOLETO / FICHA COMPENSACAO'1249 EF.fill(driver,'/html/body/span[2]/span/span[1]/input',PagamentoBoleto.lower(), insist)1250 #Pagamento em crédito1251 elif 'cartão' and 'demais bandeiras' in formarPgto.lower():1252 sleep(1)1253 PagamentoCredito = 'CREDITO EM CONTA'1254 EF.fill(driver,'/html/body/span[2]/span/span[1]/input',PagamentoCredito.lower(), insist)1255 #pagamento em cartão porto1256 elif 'cartão' and 'porto' in formarPgto.lower():1257 PagamentoPorto = 'CARTAO CREDITO - PORTO'1258 EF.fill(driver,'/html/body/span[2]/span/span[1]/input',PagamentoPorto.lower(), insist)1259 sleep(1)1260 #confirma o tipo do pagamento1261 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li', insist)1262 1263 #numero de parcelas1264 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div[10]/div/div[2]/div/div/div/div[1]/span/fieldset/div[2]/div[1]/div/input', qtdParcelas, insist)1265 1266 #Data de vencimento da primeira parcela1267 #EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div[10]/div/div[2]/div/div/div/div[1]/span/fieldset/div[3]/div[1]/div/div/input',dataVencimento, insist)1268 1269 #premio1270 if seguradora.lower() == 'porto seguro cia' or seguradora.lower() == 'porto':1271 sleep(2)1272 #Preenche Premio Total1273 driver.execute_script(f'document.getElementById("Documento_PremioTotal2").value="{premioTotal}" ')1274 sleep(1)1275 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div[10]/div/div[2]/div/div/div/div[1]/span/fieldset/div[4]/div/div/input',insist)1276 sleep(1)1277 EF.click(driver,'/html/body/form/div[7]/div/div[2]/div[10]/div/div[2]/div/div/div/div[1]/span/fieldset/div[3]/div[2]/div/input',insist)1278 sleep(1)1279 else:1280 EF.fill(driver, '//*[@id="Documento_PremioLiqDesc"]', premio_liquido,insist, 1)1281 EF.fill(driver, '//*[@id="Documento_Adicional"]', adicional,insist, 0)1282 EF.fill(driver, '//*[@id="Documento_Custo"]', custo,insist, 0)1283 1284 EF.click(driver, '//*[@id="Documento_Juros"]',insist)1285 EF.gravar(driver, '//*[@id="BtGravar"]', insist)1286 driver.switch_to.default_content()1287 alertmoeda = '/html/body/div[3]/div'1288 alert = '/html/body/div[4]/div'1289 try:1290 try:1291 if driver.find_element(By.XPATH,alert):1292 EF.click(driver,'/html/body/div[4]/div/div[3]/button[1]',insist)1293 except:pass1294 try:1295 if driver.find_element(By.XPATH,alertmoeda):1296 EF.click(driver,'/html/body/div[3]/div/div[3]/button[1]',insist)1297 except:pass1298 except:pass1299 except ValueError as err:1300 raise ValueError(err)1301 except Exception as err:1302 raise Exception('Erro - Preencher prêmio')1303 def primeiratela(driver,wait,rs):1304 try:1305 driver.switch_to.frame('Documento')1306 1307 fieldUsuario = '/html/body/form/div[7]/div/div[2]/div[1]/div/div[1]/div[2]/div[11]/div[3]/div/div[2]/div[1]/div[2]/div/span/span[1]/span/span[1]'1308 usuario = EF.getText(driver,fieldUsuario,1,'innerText')1309 #Selecionar tipo de endosso1310 EF.click(driver, '//*[@id="DIVDocumento_TipoDocumento"]/div/span/span[1]/span', insist)1311 EF.fill(driver, '/html/body/span[2]/span/span[1]/input',tipoEndosso, insist)1312 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li', insist)1313 1314 #Selecionar subtipo de endosso1315 EF.click(driver, '//*[@id="select2-Documento_SubTipo-container"]', insist)1316 EF.fill(driver, '/html/body/span[2]/span/span[1]/input',subtipoEndosso, insist)1317 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li', insist)1318 AjusteCadastral(driver,wait)1319 driver.switch_to.default_content()1320 driver.switch_to.frame('ZonaInterna')1321 driver.switch_to.frame('ZonaInterna')1322 driver.switch_to.frame('Documento')1323 1324 #Inicio da vigencia1325 sleep(2)1326 EF.fill(driver, '//*[@id="Documento_InicioVigencia"]', inicioVigencia, insist)1327 1328 sleep(2)1329 #colocar data protocolo cia1330 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div[1]/div/div[1]/div[2]/div[7]/div[3]/div/div/input',inicioVigencia, insist)1331 #data proposta1332 inputDataProposta = '/html/body/form/div[7]/div/div[2]/div[1]/div/div[1]/div[2]/div[7]/div[2]/div/div/input'1333 valueInputDataProposta = EF.getText(driver, inputDataProposta,1,'value')1334 dataCadastro = date.today()1335 dataCadastro = datetime.strftime(dataCadastro, '%d/%m/%Y')1336 sleep(2)1337 if valueInputDataProposta == '':1338 EF.fill(driver,inputDataProposta,dataCadastro,clear=1)1339 else:1340 EF.fill(driver,inputDataProposta,dataCadastro,clear=1)1341 1342 #Numero proposta cia1343 sleep(2)1344 EF.fill(driver, '//*[@id="Documento_PropostaCia"]', nupropostacia, insist)1345 1346 #Abrir dados complementares1347 EF.click(driver, '//*[@id="TitDadosComplementares"]', insist)1348 1349 #Escrever dados complementares1350 EF.fill(driver, '/html/body/form/div[7]/div/div[2]/div[2]/div/div[2]/div[2]/div/div/textarea', 'Número do registro: {}'.format(rs), insist)1351 1352 #Clica em gravar1353 sleep(2)1354 driver.execute_script("evento('Gravar')")1355 sleep(2)1356 driver.switch_to.default_content()1357 #faz a verificação dos Alerts 1358 alert = '/html/body/div[3]/div'1359 novoalert = '/html/body/div[4]/div'1360 textoAlert = '/html/body/div[3]/div/div[2]/div[1]/div'1361 textonovoAlert = '/html/body/div[4]/div/div[2]/div[1]/div'1362 sleep(3)1363 ChaveAlert = False1364 try:1365 if driver.find_elements(By.XPATH,alert) or driver.find_elements(By.XPATH,novoalert):1366 try:1367 textAlert = driver.find_element(By.XPATH,textoAlert).get_attribute('innerText').lower()1368 ChaveAlert = True1369 except:pass1370 if ChaveAlert == False:1371 textonovoAlert = driver.find_element(By.XPATH,textonovoAlert).get_attribute('innerText').lower()1372 try:1373 if 'já possui uma proposta' in textAlert: 1374 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[1]',insist)1375 1376 except:pass1377 try:1378 if 'já possui uma proposta' in textonovoAlert:1379 EF.click(driver,'/html/body/div[4]/div/div[2]/div[1]/div/div/button[1]',insist)1380 except:pass1381 try:1382 if 'nível corretora' in textAlert:1383 EF.click(driver,'/html/body/div[3]/div/div[2]/div[1]/div/div/button[1]',insist)1384 1385 sleep(3)1386 except:pass1387 try:1388 if 'nível corretora' in textonovoAlert:1389 EF.click(driver,'/html/body/div[4]/div/div[2]/div[1]/div/div/button[1]',insist)1390 except:pass1391 except:pass1392 #Fim da verificação1393 driver.switch_to.frame('ZonaInterna')1394 driver.switch_to.frame('ZonaInterna')1395 driver.switch_to.frame('Documento')1396 sleep(5)1397 #Pega o numero da proposta do Quiver1398 nupropostaquiver = EF.getText(driver, '/html/body/form/div[7]/div/div[2]/div[1]/div/div[1]/div[2]/div[7]/div[1]/div/input', insist, 'value')1399 conn = pymssql.connect(server=GC.server, user=GC.user, password=GC.password, database=GC.database)1400 cursor = conn.cursor()1401 updatenuPropostaQuiver = f""" UPDATE cockpit_mds_endosso SET noPropostaQuiver = '{nupropostaquiver}' WHERE rs = {rs} """1402 cursor.execute(updatenuPropostaQuiver)1403 conn.commit()1404 conn.close()1405 except ValueError as err:1406 raise ValueError(err)1407 except Exception as err:1408 raise Exception('Erro - Sistema Quiver')1409 def findClient(driver,wait,rs):1410 try:1411 #Começa a procurar cliente1412 driver.execute_script("SelecionaModuloJQuery('ConsultaEmissaoERecusa;Fast/FrmCadastroNovo.aspx?pagina=Documento','EMISSOESRECUSAS','Professional','EMISSOESRECUSAS','Propostas/Apólices'); ")1413 driver.switch_to.frame('ZonaInterna')1414 1415 EF.click(driver, '/html/body/form/div[5]/div[1]/div/div/div[2]/div[1]/div[2]/div/div/span/span[1]/span/span[1]', insist)1416 1417 #Pesquisa por NºApólice1418 EF.click(driver, '/html/body/span[2]/span/span[2]/ul/li[2]', insist)1419 1420 #Insere nºApólice1421 fieldNumApolice = '/html/body/form/div[5]/div[1]/div/div/div[2]/div[1]/div[4]/div[1]/div[1]/div/input'1422 EF.fill(driver, fieldNumApolice, nuapolice, insist)1423 1424 #Selecionar Situação - O PADRÃO É SELECINAR AS APÓLICES COM A SITUAÇÃO ATIVA1425 fieldSituacaoAtiva = '/html/body/form/div[5]/div[1]/div/div/div[2]/div[1]/div[4]/div[2]/div/div/div/label[2]/input'1426 EF.click(driver, fieldSituacaoAtiva, insist)1427 # #Aperta o botão de pesquisar1428 btnPesquisar = '/html/body/form/div[5]/div[1]/div/div/div[2]/div[4]/div[2]/span[1]/button'1429 EF.click(driver, btnPesquisar, insist)1430 #Volta frame para validar existência de alert1431 driver.switch_to.default_content()1432 1433 alert = '/html/body/div[3]/div'1434 try:1435 wait.until(EC.visibility_of_element_located((By.XPATH,alert)))1436 findAlert = True1437 except:1438 findAlert = False1439 if findAlert == True:1440 raise ValueError('Erro - Apólice não Localizada')1441 else:1442 print('Apólice Localizada')1443 1444 EF.acessarframe(driver,'ZonaInterna',1)1445 time.sleep(2)1446 EF.click(driver, '/html/body/form/div[5]/div[2]/div[2]/div/div[3]/div[3]/div/table/tbody/tr[2]/td[1]/a/span',insist)1447 sleep(5)1448 driver.switch_to.frame('ZonaInterna')1449 driver.execute_script('AbreEndosso()')1450 time.sleep(5)1451 except ValueError as err:1452 raise ValueError(err)1453 except Exception as err:1454 print(err)1455 1456 def terminaRobo(driver,rs,chave):1457 #Validação que verifica se a cidade foi preenchida ou não1458 dataCadastro = date.today()1459 dataCadastro = datetime.strftime(dataCadastro, '%d/%m/%Y')1460 if chave == True:1461 conn = pymssql.connect(server=GC.server, user=GC.user, password=GC.password, database=GC.database)1462 cursor = conn.cursor()1463 updateStatus = f""" UPDATE cockpit_mds_endosso SET status = 'Concluido - S/ Cidade Veículo', statusRPA = 'Proposta cadastrada',dataCadastroQuiver = '{dataCadastro}' WHERE rs = {rs} """1464 cursor.execute(updateStatus)1465 conn.commit()1466 conn.close()1467 driver.quit()1468 else:1469 conn = pymssql.connect(server=GC.server, user=GC.user, password=GC.password, database=GC.database)1470 cursor = conn.cursor()1471 updateStatus = f""" UPDATE cockpit_mds_endosso SET status = 'Concluido', statusRPA = 'Proposta cadastrada' ,dataCadastroQuiver = '{dataCadastro}' WHERE rs = {rs} """1472 cursor.execute(updateStatus)1473 conn.commit()1474 conn.close()1475 driver.quit()1476 def initWebDriver():1477 try:1478 driver = webdriver.Chrome(service=Service('./chromedriver.exe'))1479 wait = WebDriverWait(driver, 10, poll_frequency=5)1480 sleep(2)1481 try:1482 driver.get(GC.quiver)1483 except:pass1484 sleep(2)1485 driver.maximize_window()1486 return driver, wait1487 except Exception as err:1488 print(err)1489 raise ValueError('Erro - Não entrou no Quiver')1490 def main(rs):1491 try:1492 conn = pymssql.connect(server=GC.server, user=GC.user, password=GC.password, database=GC.database)1493 cursor = conn.cursor()1494 select = """ SELECT seguradora, tipoDeEndosso, subtipoDeEndosso, rs FROM cockpit_mds_endosso WHERE rs = {} """.format(rs)1495 cursor.execute(select)1496 row = cursor.fetchone()1497 seguradora = row[0]1498 tipoEndosso = row[1]1499 subtipoEndosso = row[2]1500 if tipoEndosso == 'Endosso de Cobrança':1501 if subtipoEndosso == 'Substituição de itens':1502 driver, wait = initWebDriver()1503 findClient(driver,wait,rs)1504 primeiratela(driver,wait,rs)1505 chave = CadastroProduto(driver,wait,rs)1506 preenchepremio(driver)1507 cadastraConsultor(driver)1508 importarquivos(driver)1509 terminaRobo(driver,rs,chave)1510 1511 except Exception as err:1512 EF.saveErro(driver,rs,err)1513 ...

Full Screen

Full Screen

probability_conf.py

Source:probability_conf.py Github

copy

Full Screen

1import random2from typing import Dict, List34import numpy as np56from maxland.parameter_handler import TrialParameterHandler789class ProbabilityConstructor:10 """11 Module to calculate and handle stimulus sides for the confidentiality task12 Args:13 settings (TrialParameterHandler object): the object for all the session parameters from TrialParameterHandler14 """1516 def __init__(self, settings: TrialParameterHandler):17 self.settings = settings18 self.stimulus_sides: Dict[str, bool] = {"right": False, "left": False}19 # insist mode tracking20 self.insist_mode_chosen_side_li: List[str] = list()21 self.insist_mode_active = False22 self.insist_side = ""23 self.active_rule = "RU0" # id of active rule24 self.is_initial_rule_active = True2526 def get_random_side(self):27 # check insist mode28 if self.insist_mode_active:29 if self.insist_side == "left":30 random_right = False31 elif self.insist_side == "right":32 random_right = True33 else:34 random_right = bool(random.getrandbits(1))3536 self.stimulus_sides["right"] = random_right37 self.stimulus_sides["left"] = not (random_right)3839 def get_stimulus_side(self, trial):40 """41 Args:42 trial (Trial object): the current bpod trial object43 Returns:44 current_side (str): the side the stimulus is on45 """46 # get chosen side47 if not np.isnan(trial.states_durations["check_reward_left"][0][0]):48 current_side = "left"49 print("current side: left")50 elif not np.isnan(trial.states_durations["check_reward_right"][0][0]):51 current_side = "right"52 print("current side: right")53 else:54 current_side = "non"55 self.settings.chosen_sides_history.append(current_side)56 # check if current trial side == correct side57 if current_side == "right" and self.stimulus_sides["right"]:58 self.settings.trials_correct_side_history.append(True)59 self.current_trial_correct_side_chosen = True60 elif current_side == "left" and self.stimulus_sides["left"]:61 self.settings.trials_correct_side_history.append(True)62 self.current_trial_correct_side_chosen = True63 else:64 self.settings.trials_correct_side_history.append(False)65 self.current_trial_correct_side_chosen = False66 return current_side6768 def insist_mode_check(self):69 # check for insist mode activate70 if not self.insist_mode_active:71 if len(self.settings.chosen_sides_history) >= self.settings.insist_range_trigger:72 chosen_sides_li_slice = self.settings.chosen_sides_history[-self.settings.insist_range_trigger :]73 else:74 chosen_sides_li_slice = self.settings.chosen_sides_history75 left_num_chosen = sum(map(lambda x: x == "left", chosen_sides_li_slice))76 right_num_chosen = sum(map(lambda x: x == "right", chosen_sides_li_slice))77 if left_num_chosen >= self.settings.insist_range_trigger:78 self.insist_mode_active = True79 print(self.insist_mode_active)80 self.settings.chosen_sides_history = []81 self.insist_side = "right"82 self.settings.insist_mode_history.append(self.insist_side)83 print("\n--------------------------------\n")84 print("INSIST MODE ACTIVATED: insist right")85 print("\n--------------------------------\n")86 return87 if right_num_chosen >= self.settings.insist_range_trigger:88 self.insist_mode_active = True89 self.settings.chosen_sides_history = []90 self.insist_side = "left"91 self.settings.insist_mode_history.append(self.insist_side)92 print("\n--------------------------------\n")93 print("INSIST MODE ACTIVATED: insist left")94 print("\n--------------------------------\n")95 return96 return97 # deactivate insist mode98 if self.insist_mode_active:99 self.insist_mode_chosen_side_li.append(self.settings.chosen_sides_history[-1])100 if len(self.insist_mode_chosen_side_li) >= self.settings.insist_range_deactivate:101 chosen_sides_li_slice = self.insist_mode_chosen_side_li[-self.settings.insist_range_deactivate :]102 else:103 chosen_sides_li_slice = self.insist_mode_chosen_side_li104 # check range if correct105 insist_correct_choice = sum(map(lambda x: x == self.insist_side, chosen_sides_li_slice))106 if insist_correct_choice >= self.settings.insist_correct_deactivate:107 self.insist_mode_active = False108 self.insist_side = None109 self.settings.insist_mode_history.append("none")110 self.insist_mode_chosen_side_li = []111 print("\n---------------------\n")112 print("INSIST MODE DEACTIVATED")113 print("\n---------------------\n")114115 def rule_switch_check(self, current_trial_num):116 if current_trial_num >= self.settings.rule_switch_initial_trials_wait:117 rule_switch_range = self.settings.trials_correct_side_history[self.settings.rule_switch_initial_trials_wait :]118 # > not >= because trial counter in main states loop starts from 1 not 0119 if len(rule_switch_range) >= self.settings.rule_switch_check_trial_range:120 rule_switch_range_slice = rule_switch_range[-self.settings.rule_switch_check_trial_range :]121 correct_chosen = sum(rule_switch_range_slice)122 # check if rule switch123 if self.is_initial_rule_active:124 if correct_chosen >= self.settings.rule_switch_trials_correct_trigger_switch:125 self.active_rule = "RU1" # switch to rule 1126127 self.is_initial_rule_active = False # deactivate rule switch128 print("\n--------------------------------\n")129 print("\n switch to rule RU1\n")130 print("\n--------------------------------\n")131 # invert stimulus configuration132 bk = self.settings.stimulus_correct_side.copy()133 self.settings.stimulus_correct_side = self.settings.stimulus_wrong_side.copy()134 self.settings.stimulus_wrong_side = bk ...

Full Screen

Full Screen

testing.py

Source:testing.py Github

copy

Full Screen

1###############################################################################2#3# Copyright 2013 by Shoobx, Inc.4#5###############################################################################6"""insist -- Persistence to ini files7Test helpers.8"""9import zope.component10from z3c.insist import insist11def setUpSerializers():12 zope.component.provideAdapter(insist.TextFieldSerializer)13 zope.component.provideAdapter(insist.TextLineFieldSerializer)14 zope.component.provideAdapter(insist.IntFieldSerializer)15 zope.component.provideAdapter(insist.DecimalFieldSerializer)16 zope.component.provideAdapter(insist.ChoiceFieldSerializer)17 zope.component.provideAdapter(insist.ListFieldSerializer)18 zope.component.provideAdapter(insist.TupleFieldSerializer)19 zope.component.provideAdapter(insist.BoolFieldSerializer)20 zope.component.provideAdapter(insist.DateFieldSerializer)21 zope.component.provideAdapter(insist.DateTimeFieldSerializer)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run elementium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful