lundi 27 janvier 2020

Website reloads when I click in the search button with selenium

I'm doing an automated search in a website, but when I click in the button or submit the form the website reloads and delete my filter. I think that the problem is in one function of the website.

This is the website:

http://www.tjpe.jus.br/consultajurisprudenciaweb/xhtml/consulta/consulta.xhtml

Function

function dpf(f) {var adp = f.adp;if (adp != null) {for (var i = 0;i < adp.length;i++) {f.removeChild(adp[i]);}}};function apf(f, pvp) {var adp = new Array();f.adp = adp;var i = 0;for (k in pvp) {var p = document.createElement("input");p.type = "hidden";p.name = k;p.value = pvp[k];f.appendChild(p);adp[i++] = p;}};function jsfcljs(f, pvp, t) {apf(f, pvp);var ft = f.target;if (t) {f.target = t;}f.submit();f.target = ft;dpf(f);};

There is an "on-click" in the website like this:

onclick="if(typeof jsfcljs == 'function'){jsfcljs(document.getElementById('formPesquisaJurisprudencia'),{'formPesquisaJurisprudencia:j_id112':'formPesquisaJurisprudencia:j_id112'},'');}return false"

My selenium and python code:

import time
import os
import seleniumrequests
from selenium import webdriver
from seleniumrequests import Chrome
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

chrome_options = Options()
chrome_options.add_experimental_option('prefs',  {
    "download.prompt_for_download": False,
    "download.directory_upgrade": True,
    "plugins.always_open_pdf_externally": True
    }
)

estado = str(input("Em qual estado você deseja fazer a busca?\n")) 

if (estado.upper() == 'PE'): #Mudar para "Case" quando houver outros estados
    med = str(input("Qual medicamento você deseja procurar?\n"))

    driver = webdriver.Chrome()

    driver.get('http://www.tjpe.jus.br/consultajurisprudenciaweb/xhtml/consulta/consulta.xhtml')

    driver.find_element_by_id('formPesquisaJurisprudencia:inputBuscaSimples').send_keys(med)

    driver.find_element_by_id('//*[@id="formPesquisaJurisprudencia"]/div[5]/div/a[1]').click()

    driver.find_element_by_xpath('//*[@id="resultadoForm:j_id20_body"]/div/table/tbody/tr[1]/td[2]/a').click()

    driver.find_element_by_name('j_id77:j_id80').click()



Aucun commentaire:

Enregistrer un commentaire