Vídeo recomendado
https://youtu.be/diWPPPhW-9E
https://youtu.be/diWPPPhW-9E
Vba selecionar e clicar em Listbox do IE
-
- Acabou de chegar
- Mensagens: 3
- Registrado em: Ter Abr 14, 2020 9:27 pm
Vba selecionar e clicar em Listbox do IE
Olá pessoal do fórum, estou automatizando uma atividade da empresa, e um intranet interno tem uma caixa de listagem onde devo selecionar dados, porém não estou conseguindo fazê-lo com o código que tenho, conseguem me dar uma ajuda? segue a inspeção do elemento dessa listagem:
<select class="clsSelectControl" id="PRMT_COUNTRY_NS" aria-invalid="true"
aria-multiselectable="true" aria-required="true" style='width: 125px; height: 100px;
font-family: "Calibri"; font-size: 12pt; max-height: none;' size="11" multiple="">
<option value="EUA" dv="EUA">EUA</option>
<option value="CAN" dv="CAN">CAN</option>
<option value="BRA" dv="BRA">BRA</option>
</select>
Estou usando o vba abaixo para seleconar a opção BRA no listbox:
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub SITE()
Dim ie As InternetExplorer
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
apiShowWindow ie.hwnd, SW_MAXIMIZE
ie.Navigate "https:intranetdaempresa.com"
While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
ie.Document.getElementById("PRMT_COUNTRY_NS").Focus
ie.Document.getElementById("PRMT_COUNTRY_NS").selectedIndex = 2
ie.Document.getElementById("PRMT_COUNTRY_NS").Click
ie.Quit
End Sub
Já usei o "get" para class, para id, document.all.item, mas todos mostram erro 424 "object required", as bibliotecas Microsoft Internet Controls, VB for Applications estão habilitadas também.
Não sei se ajuda, gravei com o Selenium IDE o passo a passo deste click para tentar pegar o nome de botão ou comando, mas não sei com traduzir para o VBA, pois o Selenium não tem opção de exportar para o VBA, segue o passo desta lista:
{
"id": "15f29f61-4af2-487e-872d-25d20f18299f",
"comment": "",
"command": "addSelection",
"target": "id=PRMT_COUNTRY_NS",
"targets": [
["id=PRMT_COUNTRY_NS", "id"],
["css=#PRMT_COUNTRY_NS", "css:finder"],
["xpath=//select[@id='PRMT_COUNTRY_NS']", "xpath:attributes"],
["xpath=//div[@id='PRMT_COUNTRY_NS']/select", "xpath:idRelative"],
["xpath=//select", "xpath:position"]
],
"value": "label=BRA"
}
Desde já obrigado
<select class="clsSelectControl" id="PRMT_COUNTRY_NS" aria-invalid="true"
aria-multiselectable="true" aria-required="true" style='width: 125px; height: 100px;
font-family: "Calibri"; font-size: 12pt; max-height: none;' size="11" multiple="">
<option value="EUA" dv="EUA">EUA</option>
<option value="CAN" dv="CAN">CAN</option>
<option value="BRA" dv="BRA">BRA</option>
</select>
Estou usando o vba abaixo para seleconar a opção BRA no listbox:
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow" _
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Sub SITE()
Dim ie As InternetExplorer
Set ie = CreateObject("InternetExplorer.application")
ie.Visible = True
apiShowWindow ie.hwnd, SW_MAXIMIZE
ie.Navigate "https:intranetdaempresa.com"
While ie.Busy Or ie.ReadyState <> READYSTATE_COMPLETE: DoEvents: Wend
ie.Document.getElementById("PRMT_COUNTRY_NS").Focus
ie.Document.getElementById("PRMT_COUNTRY_NS").selectedIndex = 2
ie.Document.getElementById("PRMT_COUNTRY_NS").Click
ie.Quit
End Sub
Já usei o "get" para class, para id, document.all.item, mas todos mostram erro 424 "object required", as bibliotecas Microsoft Internet Controls, VB for Applications estão habilitadas também.
Não sei se ajuda, gravei com o Selenium IDE o passo a passo deste click para tentar pegar o nome de botão ou comando, mas não sei com traduzir para o VBA, pois o Selenium não tem opção de exportar para o VBA, segue o passo desta lista:
{
"id": "15f29f61-4af2-487e-872d-25d20f18299f",
"comment": "",
"command": "addSelection",
"target": "id=PRMT_COUNTRY_NS",
"targets": [
["id=PRMT_COUNTRY_NS", "id"],
["css=#PRMT_COUNTRY_NS", "css:finder"],
["xpath=//select[@id='PRMT_COUNTRY_NS']", "xpath:attributes"],
["xpath=//div[@id='PRMT_COUNTRY_NS']/select", "xpath:idRelative"],
["xpath=//select", "xpath:position"]
],
"value": "label=BRA"
}
Desde já obrigado
Re: Vba selecionar e clicar em Listbox do IE
IE.Document.getElementById("PRMT_COUNTRY_NS").Value = "BRA"
IE.Document.getElementsByClassName("clsSelectControl")(0).Value = "BRA"
IE.Document.getElementsByTagName("select")(0).Value = "BRA"
Algum desses deve funcionar, se tiver outras classes "clsSelectControl" ou tags "select" muda o indice, esta como "0" considerando que o seu é o 1ª ou único elemento com essas caracteristicas na página. Se nao funcionar posta o html todo da pagina pra analise.
IE.Document.getElementsByClassName("clsSelectControl")(0).Value = "BRA"
IE.Document.getElementsByTagName("select")(0).Value = "BRA"
Algum desses deve funcionar, se tiver outras classes "clsSelectControl" ou tags "select" muda o indice, esta como "0" considerando que o seu é o 1ª ou único elemento com essas caracteristicas na página. Se nao funcionar posta o html todo da pagina pra analise.
-
- Acabou de chegar
- Mensagens: 3
- Registrado em: Ter Abr 14, 2020 9:27 pm
Re: Vba selecionar e clicar em Listbox do IE
Olá, realmente não consigo clicar nas caixas de seleção da página deste intranet, estou anexando o html da página, o código inteiro é muito extenso, estou deixando a parte de uma das listbox. Preciso selecionar as opções da caixa de listagem que estão como SPC ou SPA ou SAD, segue:
}
</script><table id="rt_NS_" cellpadding="0" cellspacing="0" border="0" onmousemove="if (typeof window.oCVSC_NS_ != 'undefined') window.oCVSC_NS_.pageHover(event);" onclick="window.oCV_NS_.rvMainWnd.pageClicked(event);" onkeydown="window.oCV_NS_.onKeyDown(event);" onDblClick="if (typeof window.oCVSC_NS_ != 'undefined') window.oCVSC_NS_.pageDoubleClicked(event);" onContextMenu="window.oCV_NS_.dcm(event, true)" style="font-family:"OpenSans";background-color:#E8EAFE;" class="pp" LID="Prompt_NS_"><tr><td class="hp"><table style="border-top-width:1pt;border-bottom-width:1pt;border-top-color:#000000;border-bottom-color:#000000;border-top-style:solid;border-bottom-style:solid;border-collapse:collapse;width:100%;height:30px;" class="tb" cellpadding="0"><tr><td><span tabIndex="0" style="font-family:"Calibri";font-style:normal;font-weight:bold;font-size:20pt;color:#177BA9;" LID="Title1_NS_">MODS History On the Web</span></td><td style="text-align:right;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;">Report generated: </span><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;">01/07/2020 16:51:18 GMT-04:00</span><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;"> - </span><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;padding-right:3px;">DZ3VTJ</span></td></tr></table></td></tr><tr><td class="py"><table style="border-collapse:collapse;width:100%;" class="tb" cellpadding="0"><tr><td style="padding-left:13px;vertical-align:bottom;text-align:left;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;" class="cls1">Region</span></td><td style="padding-left:28px;width:10px;vertical-align:bottom;white-space:nowrap;text-align:left;"><span tabIndex="0" style="font-family:"OpenSans";font-weight:bold;font-size:14pt;" class="cls1">MGO Code/Name</span></td><td style="padding-left:28px;width:15%;vertical-align:bottom;text-align:left;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;" class="cls1">Plant</span></td><td style="padding-left:28px;vertical-align:bottom;text-align:left;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;" class="cls1">Part Number</span></td><td style="padding-left:28px;width:15%;vertical-align:bottom;white-space:nowrap;text-align:left;"><span tabIndex="0" style="font-family:"OpenSans";font-weight:bold;font-size:14pt;" class="cls1">DUNS Number</span></td><td style="width:10px;"></td><td style="padding-left:22px;width:25%;"></td></tr><tr><td style="vertical-align:top;text-align:left;"><div id="PRMT_N167C7080x265F9754_NS_" class="clsPromptComponent"></div><select id="PRMT_SV_N167C7080x265F9754_NS_" class="clsSelectControl pv" multiple><option value="SAD" dv="SAD">SAD</option><option value="SPA" dv="SPA">SPA</option><option value="SPC" dv="SPC">SPC</option></select><script language="javascript" type="text/javascript">
G_PM_NS_.F_Add({n:'selectValue',"@layoutClass":"selectValue","@parameter":"REGION_CD","@range":false,"@required":true,"@hideAdornments":false,"@multiSelect":true,"@refQuery":"Q_Region","@prePopulateIfParentOptional":false,"@selectValueUI":"listBox","@rowsPerPage":"5000","@autoSubmit":true,"@name":"_P1706623722","@style":"font-family:\"Calibri\";font-size:12pt;width:125px;height:100px","@resultsDeselectAllText":"","@resultsSelectAllText":"","@autoCascade":true,c:[{n:'selectOptions',c:[{n:'selectOption',"@layoutClass":"useItem","@refDataItem":"REGION_CD","@useValue":"SAD","@displayValue":"SAD"},{n:'selectOption',"@layoutClass":"useItem","@refDataItem":"REGION_CD","@useValue":"SPA","@displayValue":"SPA"},{n:'selectOption',"@layoutClass":"useItem","@refDataItem":"REGION_CD","@useValue":"SPC","@displayValue":"SPC"}]}]},{_id_:'N167C7080x265F9754_NS_',CVId:'_NS_'});
</script></td><td style="padding-left:15px;vertical-align:top;text-align:left;"><div id="PRMT_N167C7080x265F9830_NS_" class="clsPromptComponent"></div><select id="PRMT_SV_N167C7080x265F9830_NS_" class="clsSelectControl pv" multiple></select><script language="javascript" type="text/javascript">
G_PM_NS_.F_Add({n:'selectValue',"@layoutClass":"selectValue","@parameter":"MGO","@range":false,"@required":true,"@hideAdornments":false,"@multiSelect":true,"@refQuery":"Q_MGO Name","@cascadeOn":"REGION_CD","@prePopulateIfParentOptional":false,"@selectValueUI":"listBox","@rowsPerPage":"5000","@autoSubmit":true,"@name":"_P572094522","@style":"font-family:\"Calibri\";font-size:12pt;width:1.700000in;height:100px","@resultsDeselectAllText":"","@resultsSelectAllText":"","@disabled":true,"@autoCascade":true},{_id_:'N167C7080x265F9830_NS_',CVId:'_NS_'});
</script></td><td style="padding-left:15px;vertical-align:top;text-align:left;"><div id="PRMT_N167C7080x265F9888_NS_" class="clsPromptComponent"></div><select id="PRMT_SV_N167C7080x265F9888_NS_" class="clsSelectControl pv" multiple></select><script language="javascript" type="text/javascript">
Obrigado
}
</script><table id="rt_NS_" cellpadding="0" cellspacing="0" border="0" onmousemove="if (typeof window.oCVSC_NS_ != 'undefined') window.oCVSC_NS_.pageHover(event);" onclick="window.oCV_NS_.rvMainWnd.pageClicked(event);" onkeydown="window.oCV_NS_.onKeyDown(event);" onDblClick="if (typeof window.oCVSC_NS_ != 'undefined') window.oCVSC_NS_.pageDoubleClicked(event);" onContextMenu="window.oCV_NS_.dcm(event, true)" style="font-family:"OpenSans";background-color:#E8EAFE;" class="pp" LID="Prompt_NS_"><tr><td class="hp"><table style="border-top-width:1pt;border-bottom-width:1pt;border-top-color:#000000;border-bottom-color:#000000;border-top-style:solid;border-bottom-style:solid;border-collapse:collapse;width:100%;height:30px;" class="tb" cellpadding="0"><tr><td><span tabIndex="0" style="font-family:"Calibri";font-style:normal;font-weight:bold;font-size:20pt;color:#177BA9;" LID="Title1_NS_">MODS History On the Web</span></td><td style="text-align:right;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;">Report generated: </span><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;">01/07/2020 16:51:18 GMT-04:00</span><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;"> - </span><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;color:#666666;padding-right:3px;">DZ3VTJ</span></td></tr></table></td></tr><tr><td class="py"><table style="border-collapse:collapse;width:100%;" class="tb" cellpadding="0"><tr><td style="padding-left:13px;vertical-align:bottom;text-align:left;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;" class="cls1">Region</span></td><td style="padding-left:28px;width:10px;vertical-align:bottom;white-space:nowrap;text-align:left;"><span tabIndex="0" style="font-family:"OpenSans";font-weight:bold;font-size:14pt;" class="cls1">MGO Code/Name</span></td><td style="padding-left:28px;width:15%;vertical-align:bottom;text-align:left;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;" class="cls1">Plant</span></td><td style="padding-left:28px;vertical-align:bottom;text-align:left;"><span tabIndex="0" style="font-family:"Calibri";font-weight:bold;font-size:14pt;" class="cls1">Part Number</span></td><td style="padding-left:28px;width:15%;vertical-align:bottom;white-space:nowrap;text-align:left;"><span tabIndex="0" style="font-family:"OpenSans";font-weight:bold;font-size:14pt;" class="cls1">DUNS Number</span></td><td style="width:10px;"></td><td style="padding-left:22px;width:25%;"></td></tr><tr><td style="vertical-align:top;text-align:left;"><div id="PRMT_N167C7080x265F9754_NS_" class="clsPromptComponent"></div><select id="PRMT_SV_N167C7080x265F9754_NS_" class="clsSelectControl pv" multiple><option value="SAD" dv="SAD">SAD</option><option value="SPA" dv="SPA">SPA</option><option value="SPC" dv="SPC">SPC</option></select><script language="javascript" type="text/javascript">
G_PM_NS_.F_Add({n:'selectValue',"@layoutClass":"selectValue","@parameter":"REGION_CD","@range":false,"@required":true,"@hideAdornments":false,"@multiSelect":true,"@refQuery":"Q_Region","@prePopulateIfParentOptional":false,"@selectValueUI":"listBox","@rowsPerPage":"5000","@autoSubmit":true,"@name":"_P1706623722","@style":"font-family:\"Calibri\";font-size:12pt;width:125px;height:100px","@resultsDeselectAllText":"","@resultsSelectAllText":"","@autoCascade":true,c:[{n:'selectOptions',c:[{n:'selectOption',"@layoutClass":"useItem","@refDataItem":"REGION_CD","@useValue":"SAD","@displayValue":"SAD"},{n:'selectOption',"@layoutClass":"useItem","@refDataItem":"REGION_CD","@useValue":"SPA","@displayValue":"SPA"},{n:'selectOption',"@layoutClass":"useItem","@refDataItem":"REGION_CD","@useValue":"SPC","@displayValue":"SPC"}]}]},{_id_:'N167C7080x265F9754_NS_',CVId:'_NS_'});
</script></td><td style="padding-left:15px;vertical-align:top;text-align:left;"><div id="PRMT_N167C7080x265F9830_NS_" class="clsPromptComponent"></div><select id="PRMT_SV_N167C7080x265F9830_NS_" class="clsSelectControl pv" multiple></select><script language="javascript" type="text/javascript">
G_PM_NS_.F_Add({n:'selectValue',"@layoutClass":"selectValue","@parameter":"MGO","@range":false,"@required":true,"@hideAdornments":false,"@multiSelect":true,"@refQuery":"Q_MGO Name","@cascadeOn":"REGION_CD","@prePopulateIfParentOptional":false,"@selectValueUI":"listBox","@rowsPerPage":"5000","@autoSubmit":true,"@name":"_P572094522","@style":"font-family:\"Calibri\";font-size:12pt;width:1.700000in;height:100px","@resultsDeselectAllText":"","@resultsSelectAllText":"","@disabled":true,"@autoCascade":true},{_id_:'N167C7080x265F9830_NS_',CVId:'_NS_'});
</script></td><td style="padding-left:15px;vertical-align:top;text-align:left;"><div id="PRMT_N167C7080x265F9888_NS_" class="clsPromptComponent"></div><select id="PRMT_SV_N167C7080x265F9888_NS_" class="clsSelectControl pv" multiple></select><script language="javascript" type="text/javascript">
Obrigado
Re: Vba selecionar e clicar em Listbox do IE
Opa, se não pegou pelo ID deve ta dentro de algum Frame/IFrame , procura essa tag no codigo. Nessa parte que mandou nao tem.
-
- Acabou de chegar
- Mensagens: 3
- Registrado em: Ter Abr 14, 2020 9:27 pm
Re: Vba selecionar e clicar em Listbox do IE
Olá amigos
Peguei o código que o Selenium gravou até selecionar a opção "SPC", realmente tem Frame na página, segue a gravação do Selenium:
{
"id": "6b6a629d-9d46-4191-9a64-e291c936e3af",
"version": "2.0",
"name": "COGNOS",
"url": "site.com",
"tests": [{
"id": "88d8eb45-9fd8-476c-8b11-09f6ce312c73",
"name": "COGNOS",
"commands": [{
"id": "d661baa8-1d9d-41d0-8fef-93ea1316eacf",
"comment": "",
"command": "open",
"target": "/ibmcognos/bi/?perspective=classicviewer&id=iF6E93845149C4B238CEB13886C621090&isViewer=false&isNewFromModule=false&isNewFromPackage=false&isNewDataSetFromModule=false&isNewDataSetFromPackage=false&isTemplate=false&isDataset=false&UIProfile=Titan&cmProperties%5Bid%5D=iF6E93845149C4B238CEB13886C621090&cmProperties%5BdefaultName%5D=MODS+History+On+the+Web&cmProperties%5Btype%5D=report&cmProperties%5Bpermissions%5D%5B%5D=execute&cmProperties%5Bpermissions%5D%5B%5D=read&cmProperties%5Bpermissions%5D%5B%5D=traverse&rsFinalRunOptions%5Bformat%5D=spreadsheetML&rsFinalRunOptions%5Ba11y%5D=false&rsFinalRunOptions%5Bbidi%5D=false&rsFinalRunOptions%5BrunInAdvancedViewer%5D=false&rsFinalRunOptions%5BDownload%5D=true&rsFinalRunOptions%5Bprompt%5D=true&rsFinalRunOptions%5BisApplication%5D=false",
"targets": [],
"value": ""
}, {
"id": "df0cd83f-f71d-4e1f-b00d-1c9258f17c65",
"comment": "",
"command": "setWindowSize",
"target": "1552x840",
"targets": [],
"value": ""
}, {
"id": "b0c1cea2-a1f1-42e6-bf1f-0320764b25c1",
"comment": "",
"command": "selectFrame",
"target": "index=0",
"targets": [
["index=0"]
],
"value": ""
}, {
"id": "15f29f61-4af2-487e-872d-25d20f18299f",
"comment": "",
"command": "addSelection",
"target": "id=PRMT_SV_N1E407440x32AF0554_NS_",
"targets": [
["id=PRMT_SV_N1E407440x32AF0554_NS_", "id"],
["css=#PRMT_SV_N1E407440x32AF0554_NS_", "css:finder"],
["xpath=//select[@id='PRMT_SV_N1E407440x32AF0554_NS_']", "xpath:attributes"],
["xpath=//div[@id='PRMT_SV_CONTAINER_N1E407440x32AF0554_NS_']/select", "xpath:idRelative"],
["xpath=//select", "xpath:position"]
],
"value": "label=SPC"
}
Peguei o código que o Selenium gravou até selecionar a opção "SPC", realmente tem Frame na página, segue a gravação do Selenium:
{
"id": "6b6a629d-9d46-4191-9a64-e291c936e3af",
"version": "2.0",
"name": "COGNOS",
"url": "site.com",
"tests": [{
"id": "88d8eb45-9fd8-476c-8b11-09f6ce312c73",
"name": "COGNOS",
"commands": [{
"id": "d661baa8-1d9d-41d0-8fef-93ea1316eacf",
"comment": "",
"command": "open",
"target": "/ibmcognos/bi/?perspective=classicviewer&id=iF6E93845149C4B238CEB13886C621090&isViewer=false&isNewFromModule=false&isNewFromPackage=false&isNewDataSetFromModule=false&isNewDataSetFromPackage=false&isTemplate=false&isDataset=false&UIProfile=Titan&cmProperties%5Bid%5D=iF6E93845149C4B238CEB13886C621090&cmProperties%5BdefaultName%5D=MODS+History+On+the+Web&cmProperties%5Btype%5D=report&cmProperties%5Bpermissions%5D%5B%5D=execute&cmProperties%5Bpermissions%5D%5B%5D=read&cmProperties%5Bpermissions%5D%5B%5D=traverse&rsFinalRunOptions%5Bformat%5D=spreadsheetML&rsFinalRunOptions%5Ba11y%5D=false&rsFinalRunOptions%5Bbidi%5D=false&rsFinalRunOptions%5BrunInAdvancedViewer%5D=false&rsFinalRunOptions%5BDownload%5D=true&rsFinalRunOptions%5Bprompt%5D=true&rsFinalRunOptions%5BisApplication%5D=false",
"targets": [],
"value": ""
}, {
"id": "df0cd83f-f71d-4e1f-b00d-1c9258f17c65",
"comment": "",
"command": "setWindowSize",
"target": "1552x840",
"targets": [],
"value": ""
}, {
"id": "b0c1cea2-a1f1-42e6-bf1f-0320764b25c1",
"comment": "",
"command": "selectFrame",
"target": "index=0",
"targets": [
["index=0"]
],
"value": ""
}, {
"id": "15f29f61-4af2-487e-872d-25d20f18299f",
"comment": "",
"command": "addSelection",
"target": "id=PRMT_SV_N1E407440x32AF0554_NS_",
"targets": [
["id=PRMT_SV_N1E407440x32AF0554_NS_", "id"],
["css=#PRMT_SV_N1E407440x32AF0554_NS_", "css:finder"],
["xpath=//select[@id='PRMT_SV_N1E407440x32AF0554_NS_']", "xpath:attributes"],
["xpath=//div[@id='PRMT_SV_CONTAINER_N1E407440x32AF0554_NS_']/select", "xpath:idRelative"],
["xpath=//select", "xpath:position"]
],
"value": "label=SPC"
}