Notifications
Clear all

Atualizar combobox dependente usando VBA no html em um site

2 Posts
1 Usuários
0 Reactions
1,259 Visualizações
(@mairon)
Posts: 40
Eminent Member
Topic starter
 

Olá pessoal

Preciso manipular alguns objetos no site dos correios, esta tela:

http://www2.correios.com.br/sistemas/agencias/

Ao atualizar o primeiro combobox (estado) através de VBA, o segundo combobox (município) precisa popular sua lista.

Clicando manualmente da certinho, porém quando seleciono o estado pelo vba o combobox município não popula.

Eu tentei desta forma:

Set ie = New InternetExplorer
    ie.Visible = True
    ie.Navigate "http://www2.correios.com.br/sistemas/agencias/"

    Do Until (ie.ReadyState = 4)
    Loop


    'Combobox estado
     ie.Document.all("estadoAgencia").Item(2).Selected = True
    ie.Document.all("estadoAgencia").Item(2).Focus
    ie.Document.all("estadoAgencia").Item(2).Click
    ie.Document.all("estadoAgencia").Item(2).FireEvent ("onChange")


    'Combobox municipio
    ie.Document.all("municipioAgencia").Item(2).Selected = True      'Aqui gera o erro, pois tenta marcar o combobox porém não foi populado ainda 

Eu acho que tem que chamar alguma função, utilizando o método:

ie.Document.parentWindow.execScript ( "functionname ()") 

Estou com dificuldade em encontrar a função, tem esse bloco lá no site

<script type="text/javascript">/* <![CDATA[ */
    var _cf_cfcAgencia=ColdFusion.AjaxProxy.init('/sistemas/agencias/cfc/cfcAgencia.cfc','ProxyAjax');
    _cf_cfcAgencia.prototype.getAgenciasProximas=function(latitude,longitude) { return ColdFusion.AjaxProxy.invoke(this, "getAgenciasProximas","45A0BE8C97B5F00E", {latitude:latitude,longitude:longitude});};
    _cf_cfcAgencia.prototype.getBairro=function(UF,municipio) { return ColdFusion.AjaxProxy.invoke(this, "getBairro","45A0BE8C97B5F00E", {UF:UF,municipio:municipio});};
    _cf_cfcAgencia.prototype.getUF=function() { return ColdFusion.AjaxProxy.invoke(this, "getUF","45A0BE8C97B5F00E", {});};
    _cf_cfcAgencia.prototype.getMunicipio=function(UF) { return ColdFusion.AjaxProxy.invoke(this, "getMunicipio","45A0BE8C97B5F00E", {UF:UF});};
/* ]]> */</script>

Eu acredito que pode ser:

  _cf_cfcAgencia.prototype.getMunicipio=function(UF)

Porém não consigo dar um call nessa função, alguém pode ajudar?

Abraços

 
Postado : 25/10/2016 10:08 am
(@mairon)
Posts: 40
Eminent Member
Topic starter
 

Consegui a resposta, houveram algumas mudanças no internet explorer 9, então temos que ligar para os acontecimentos de forma diferente usando dispatchEvent ().

 Set ie = CreateObject("InternetExplorer.Application")
    ie.Visible = True
    ie.Navigate "http://www2.correios.com.br/sistemas/agencias/"

    Do Until (ie.ReadyState = 4)
    Loop


    'First combobox
'     ie.document.all("estadoAgencia").Item(2).Selected = True
'    ie.document.all("estadoAgencia").Item(2).Focus
'    ie.document.all("estadoAgencia").Item(2).Click
'    ie.document.all("estadoAgencia").Item(2).FireEvent ("onkeypress")
    Set evt = ie.document.createevent("htmlevents")
    evt.initevent "change", True, False
    Set lst = ie.document.getelementbyid("estadoAgencia")
    lst.selectedindex = 2 'select it as you were
    lst.dispatchevent evt  'Fire the event with dispatchEvent
 
Postado : 25/10/2016 1:46 pm