Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23131

Why the selenium is not locating the element

$
0
0

I'm checking if some element is clicked using selenium, but I guess it's not working. here is the code:

try:            print("espere o elemento")            container = WebDriverWait(driver, 30).until(            EC.presence_of_element_located((By.CSS_SELECTOR, ".container"))        )        # Find and click the "Mais" link            mais_link = WebDriverWait(container, 60).until(EC.element_to_be_clickable            ((By.CSS_SELECTOR, "a.unj-link-collapse")))            mais_link.click()            print("mostrou mais?")            #mais_movimentacoes = WebDriverWait(driver, 10).until(            #EC.element_to_be_clickable((By.CSS_SELECTOR, "#linkmovimentacoes"))        #)            #print("clicou")            mais_partes = WebDriverWait(driver, 60).until(EC.element_to_be_clickable(            (By.ID, "linkpartes")))            mais_partes.click()            print("clicou no mais partes")            #mais_movimentacoes = WebDriverWait(driver,10).until(            #EC.element_to_be_clickable((By.CSS_SELECTOR, "#linkmovimentacoes")))            #mais_movimentacoes.click()        except Exception as e:            # Log the exception for debugging purposes            print("Error:", e)

it never shows "clicou no mais partes" or "mostrou mais?" also, it does not find the "unj-link-collapse" class. here is the html:

<div class="unj-entity-header__details__barra"><div class="container"><div class="unj-ta-r"><a href="#maisDetalhes" class="unj-link-collapse" data-toggle="collapse" aria-expanded="false" aria-controls="maisDetalhes"><span class="unj-link-collapse__show"><i id="botaoExpandirDadosSecundarios" class="unj-link-collapse__icon glyph glyph-chevron-down"></i>                        Mais</span><span class="unj-link-collapse__hide"><i id="botaoRecolherDadosSecundarios" class="unj-link-collapse__icon glyph glyph-chevron-up"></i>                        Recolher</span></a></div>

and

<a id="linkpartes" href="javascript:" class="linkNaoSelecionado unj-link-collapse"><span id="setasDireitapartes" class="setasDireita"><i class="unj-link-collapse__icon glyph glyph-chevron-down"></i></span>        Mais</a>

here is the relevant rest of the code:

if __name__ == '__main__':    obj = Processo()    opts = FirefoxOptions()    opts.add_argument("--headless")    driver = driver.Firefox(options = opts)    url = "https://esaj.tjsp.jus.br/cpopg/open.do"    driver.get(url)    file1 = open('numerosprocesso.txt', 'r')    Lines = file1.readlines()    elementos = []    for line in Lines:        seletor = driver.find_element(By.ID, "cbPesquisa")        print("achou o seletor?")        drop = Select(seletor)        drop.select_by_value("NUMPROC")        entrada_texto_primeiraparte = driver.find_element(By.ID, "numeroDigitoAnoUnificado")        entrada_texto_segundaparte = driver.find_element(By.ID, "foroNumeroUnificado")        entrada_texto_primeiraparte.send_keys(line[0:15])        entrada_texto_segundaparte.send_keys(line[-5:])        botao = WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.ID, "botaoConsultarProcessos")))        botao.click()        elementos = obj.pegaElementos()        print(elementos)        driver.save_full_page_screenshot('processo'+ f'{line}.png')        with open('processos.csv', 'w', newline='', encoding='utf-8') as csvfile:            csv_writer = csv.writer(csvfile)            csv_writer.writerow(['Número do Processo', 'Classe', 'Foro', 'Vara', 'Juiz', 'Assunto', 'Controle','Valor', 'Distribuição','Área', 'Outros Assuntos', 'Requerente', 'Descrição', 'Data de Movimentação'])            csv_writer.writerow(elementos)            driver.back()            print(driver.current_url)

where is the error since the name of the classes and ids are correct?


Viewing all articles
Browse latest Browse all 23131

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>