PDA

View Full Version : I Can't change <SELECT> html tag using VBA



renansor
03-25-2014, 10:48 AM
Hello,

I can log-in on the system - but, when i try select the <SELECT> html tag using vba i get the error: 91
I realize what <SELECT> tag is controlled with JavaScript and i cant proceed.

Anyone, can i help me?


HTML

<select name="ctl00$cphPrincipal$ddlEmpresa" onchange="javascript:setTimeout('__doPostBack(\'ctl00$cphPrincipal$ddlEmpresa\',\'\') ', 0)" id="ctl00_cphPrincipal_ddlEmpresa" style="background-color:#EBEBEB;border-color:#E2E2E2;border-width:1px;border-style:Solid;width:140px;"><option selected="selected" value="">Selecionar Item...</option><option value="4">Pessoa Jurídica</option>

I need to change de select's state to the value 4

HTML + VBA CODE in Attachments

Sorry for my bad english! Thanks!

westconn1
03-28-2014, 02:46 AM
try using the fireevent method of the select element, after changing its value

renansor
03-28-2014, 10:16 AM
I did try like this:

ie.document.getElementById("ctl00_cphPrincipal_ddlEmpresa").selectedIndex = 4
ie.document.getElementById("ctl00_cphPrincipal_ddlEmpresa").FireEvent ("onchange")

*ctl00_cphPrincipal_ddlEmpresa - <SELECT> ID

It doesn't works - But <SELECT> stay empty instead the default value.

Anybody knows what can be?

Thanks

westconn1
03-28-2014, 10:05 PM
ie.document.getElementById("ctl00_cphPrincipal_ddlEmpresa").selectedIndex = 4according to the sample file posted above there is only 2 items for selection
only valid values for selected index would be 0 and 1, test for yourself

renansor
03-31-2014, 06:49 AM
westconn, Thank YOU!
Works!

renansor
03-31-2014, 08:29 AM
Just one more question, if the <SELECT> tag is disabled, can i select? If not, have a way to do this?

westconn1
03-31-2014, 01:40 PM
can i select?did you test? you should still be able to change values by code


If not, have a way to do this?i would assume that you can enable by code