I'm using Selenium WebDriver to realify test with python
when executing this line:
mov.find_elements_by_xpath("td")[3].text.encode('utf-8')
I have the answer:
{'descricao': 'PROTOCOLIZADA PETI\xc3\x87\xc3\x83O'},
When should you:
{'descricao': 'PROTOCOLIZADA PETIÇÃO'},
Full Code
#encoding: utf-8
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.support import ui
from app.browser_automation.browser_automation import BrowserAutomation
import time
import CONST
from datetime import datetime
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import ui
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
class BrowserAutomationTrt19(BrowserAutomation):
def page_is_loaded(self, driver):
time.sleep(2)
return True #driver.find_element_by_id("Div_HeaderMedium") != None
# consultas dos processo na base afim de procurar no portal
def make_consulta(self, numero):
#preencher os elementos da consulta
#dividir os numero em array
partes_numero_processo = self.get_partes_do_numero(numero)
#preencher os campos no formulario da página
self.browser.find_element_by_xpath("//input[contains(@id,'seq')]").send_keys(partes_numero_processo[0])
self.browser.find_element_by_xpath("//input[contains(@id,'dig')]").send_keys(partes_numero_processo[1])
self.browser.find_element_by_xpath("//input[contains(@id,'ano')]").send_keys(partes_numero_processo[2])
self.browser.find_element_by_xpath("//input[contains(@id,'org')]").send_keys(partes_numero_processo[5])
#clicar no butão buscar
self.browser.find_element_by_xpath("//input[contains(@class,'btnBuscar')]").click()
#atualizar tela
self.browser.refresh
#se nao encontrar processo
#if not self.processo_naoencontrado():
#wait = ui.WebDriverWait(self.browser, 1000000000)
#else:
#CONST.PROCESSO_ENCONTRADO = False
return True
#se nao encontra processo
def processo_naoencontrado(self):
try:
return "Nenhum registro encontrado!" in self.browser.find_element_by_id('idDivBlocoMensagem').text
except:
return False
#obtendo as movimentacoes
def read_movimentacoes(self,processo):
movimentacoes = []
time.sleep(5)
#clicar no link <a>
self.browser.find_element_by_xpath("//div[contains(@class,'row-fluid')]/p[contains(@class,'lead')]/a").click()
time.sleep(2)
print 'Lendo Movimentacoes...1'
moviments = self.browser.find_elements_by_xpath("//table[contains(@id,'tableMovimentacoes1inst')]/tbody/tr")
print "teste 0"
for mov in moviments:
data_hora = mov.find_elements_by_xpath("td")
data_hora = data_hora[0].text + " " + data_hora[1].text + ":00"
data_mov = datetime.strptime(data_hora.strip(), '%d/%m/%Y %H:%M:%S')
if processo['ultima_movimentacao'] <= data_mov:
fase_movimentacao = mov.find_elements_by_xpath("td")[3].text.encode('utf-8')
mov = {'data': data_hora,
'faseMovimentacao': {'descricao': fase_movimentacao}
}
if mov not in movimentacoes:
movimentacoes.append(mov)
# print mov
else:
print "teste3"
return movimentacoes
print "teste4"
time.sleep(2)
return movimentacoes
phase_movement= mov.find_elements_by_xpath("td") [3] .text.decode ('utf-8') File "C: \ Python27 \ Lib \ encodings \ utf_8.py", line 16, in decode return codecs.utf_8_decode (input, errors, True) UnicodeEncodeError: 'ascii' codec can not encode characters in position 6-7: ordinal not in range (128)