0

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()
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • 3
    This is the site behavior. What exactly is your question? – Guy Jan 27 '20 at 19:12
  • I still don't understand what the problem is. The deleted filter? just refill it. – Guy Jan 27 '20 at 19:37
  • The problem is that the website reloads and stay in the same page, doesn't show me the results of the filter. If I do this manually it works, but in selenium it doesn't. – Vitor Caliari Jan 27 '20 at 19:47

2 Answers2

0

Try with this xpath to click on Search button:

.//div[@class='botoes-consulta']/a/font/font[text()='Search ']

Also this is not an idits xpath

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

To click on Pesquisar link induce WebDriverWait() and element_to_be_clickable and following Xpath option.

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//a[@class='form-button first' and text()='Pesquisar']"))).click()

Or following css selector.

WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"div.botoes-consulta >a.form-button.first"))).click()
KunduK
  • 32,888
  • 5
  • 17
  • 41