我的目标是从“ X”(i)单元格中选择/插入一个值到Web上的下拉元素。
使用当前代码,我希望将值插入到下拉元素的“搜索”栏中>单击下拉图标,这将打开下拉列表> 查看与该值相关的childstest值
问题是保存后更改不会发生,因为我找不到模拟下拉列表中“找到”值的左键的方法。 如果有帮助,用户可以在选择该要素上的值时采用两种方式应用更改:
- 将值插入elemtns搜索栏中>单击下拉图标 选择该值(出现几秒钟即可加载)
- 单击下拉图标>单击打开的“儿童”值图标> 左键选择所需的值。
注意:按“输入”将不起作用。它会“聚焦”无用的东西,但是如果我 将尝试保存它,不会应用任何更改。
我的VBA代码[试图将值从APAC更改为EMEA]:
Sub User_Setup()
'Application.ScreenUpdating = False
'Application.DisplayAlerts = False
'----------------------------------here I define elemnts for the loop
Dim sht As Worksheet
Set sht = ThisWorkbook.Sheets("Fields")
Dim LastRow As Long
Dim i As Long
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row
Dim values() As String
Dim b As Long
Dim frm As Object
Dim dt As Object
'---------------------------------------------here I define Internet Explorer
Dim IE As Object
Dim Doc As HTMLDocument
Set IE = CreateObject("InternetExplorer.Application")
'--------------------------------------------- here I define range for the loop
For i = 2 To LastRow
' ---------------------------------------------here I ask the Internet explorer to be visable & Navigate to value in cell "H"i
IE.Visible = True
IE.navigate sht.Range("A" & i).Value
' ---------------------------------------------here I ask the Internet explorer to wait few seconds
Do While IE.Busy
Application.Wait DateAdd("s", 1, Now)
Loop
Set Doc = IE.document
'--------------------------------- Here is my issue with the dropdown
Doc.getElementById("tab7").Click ' clicks the tab where the dropdown exists
Doc.getElementById("ResourceWorkgroup").Value = sht.Range("X" & i).Value ' This is the value needs be choosen in the dropdown
Doc.getElementById("ResourceWorkgroup").FireEvent "onfocus" ' this event should make the value just inserted be highlited
'----
Doc.getElementById("_IB_imgResourceWorkgroup").Click ' this is the action that mimic mouse click on the "open drop down" icon
Doc.getElementById("_IB_imgResourceWorkgroup").FireEvent "onfocus" 'not sure if this line is even helpful
'----
'NOTE:I manage to enter the value in the search field, and the click the dropdown list icon,
'(mimic the mouse click on the open dropdown list icon) without really choosing the value.
Application.Wait Now + TimeValue("00:00:10")
Doc.getElementById("Master_IdBtnSave").Click ' click on save button
Doc.getElementById("Master_IdBtnSave").FireEvent "*******" 'trigger the event of saving (not sure if this neccery aswell)
Next i
End Sub
以下是来自网络的html代码:
<div id="Master_cphBody_divWorkgroup">
<label class="txt" id="Master_cphBody_lblWorkgroup" for="Master_cphBody_ResourceWorkgroup"><span></span>Workgroup:</label>
<script src="/JS/InputBoxWithWkgResCusConDropdownTree.js" type="text/javascript"></script>
<script src="../../JS/inJsValidate.js" type="text/javascript"></script>
<table class="offsetLeft" style="margin: 2px;" cellspacing="0" cellpadding="0">
<tbody><tr>
<td style="border: 1px solid rgb(153, 153, 153); border-image: none; padding-left: 1px; vertical-align: middle; white-space: nowrap;">
<input name="ResourceWorkgroup" title="APAC" id="ResourceWorkgroup" style="margin: 0px; border: 0px currentColor; border-image: none; width: 380px;" onkeyup="_IBDD_InputKeyDown(this, null, event)" onfocus="this.focus();this.select();" type="text" value="APAC" controltype="TWDropDown" showclientportalparticipant="" entity="" ctype="IB" searchtt="Press ENTER or click the drop-down list and select a value." dirty="0" requiresla="0" requesttype="" additionalid="" allresources="false" allrequests="false" selectedbydblclick="0" multiselid="" multiselect="0" adjusty="0" adjustx="0" disablesearchcriteria="0" includesystem="false" ignoreaccesscheck="False" portfoliofilter="" surveyfilter="" requestfilter="" productfilter="" invoicefilter="" competitorfilter="" campaignfilter="" reportfilter="" oppfilter="" taskfilter="" prjfilter="" engfilter="" cusfilter="" wgpfilter="-2032307166" cfilter="" rfilter="" inputlength="50" smodel="3" referenceposition="" ddstyle="" ddheight="350" ddwidth="400" cptype="res" cpvalue="APAC" cpid="6c9ef9d1-daef-11d2-882b-006097b596a6" oValue="EMEA">
<span id="_IB_iconResourceWorkgroup">
<img id="_IB_imgResourceWorkgroup" style="padding-right: 2px; margin-left: -1px; cursor: pointer;" onclick="_IBDD_InputKeyDown(document.getElementById('ResourceWorkgroup'), '1', event)" src="../../Images/UI/ddSelect1.gif" ctype="IB" icon1="../../Images/UI/ddSelect1.gif">
</span>
<br>
<div id="_CPDDWRCC_div" style="width: 400px; height: 350px; margin-top: 0px; display: block; position: absolute; z-index: 1010;" cpheight="350" cpwidth="400">
<iframe id="_CPDDWRCC_ifr" src="../../UserControl/DropDownWkgResCusConTreeView/ifrDropDownWkgResCusConTreeView.aspx?rid=DA69AADD-D0A8-4551-A1E2-5FE83E99F914&ResourceId=DA69AADD-D0A8-4551-A1E2-5FE83E99F914&sno=0FA81AEE-A8AA-44B9-AE87-EF68727E874E&SessionId=0FA81AEE-A8AA-44B9-AE87-EF68727E874E&ui=W&dialog=&RDFilter=0&model=3&key=EMEA&rfilter=&cfilter=&wgpfilter=-2032307166&cusfilter=&engfilter=&prjfilter=&taskfilter=&oppfilter=&campaignfilter=&competitorfilter=&invoicefilter=&productfilter=&requestfilter=&surveyfilter=&portfoliofilter=&ignoreaccesscheck=False&reportfilter=&includesystem=false&width=400&height=350&multiSelect=0&multiselid=&selectedbydblclick=0&allrequests=false&allresources=false&additionalid=6c9ef9ce-daef-11d2-882b-006097b596a6&requesttype=6c9ef9ce-daef-11d2-882b-006097b596a6&entity=&showclientportalparticipant=" frameborder="0" scrolling="no" style="border: 1px solid rgb(153, 153, 153); border-image: none; width: 100%; height: 100%;"></iframe>
</div></td>
</tr>
</tbody></table>
</div>
编辑:以下是单击下拉列表时的html:
<div id="ddwccCPTreeBorder" style="width: 400px; height: 350px; -ms-overflow-x: scroll; -ms-overflow-y: scroll; background-color: rgb(255, 255, 255);" onclick="_CPT_onCPTreeviewClick('ddwcc', event);" ondblclick="_CPT_onCPTreeviewDblClick('ddwcc', event);" ondragstart="_CPT_OnDragStart('ddwcc', event);">
<div id="ddwccCPTree" topnode="1" blankpageurl="about:blank" dloadurl="about:blank"><div id="ddwcc6C9EF9CE_DAEF_11D2_882B_006097B596A6" style="white-space: nowrap;" cptype="gwgp" move="0" l="0" order="0"><img width="9" height="9" style="padding: 3px 1px 5px; cursor: default;" src="../../Images/Treeview/minus.gif" board="0" ct="pm"><img align="absmiddle" src="../../Images/Treeview/tvFolder.gif" border="0" hspace="3" ct="" eurl=""><span title="Services" style="cursor: pointer;"> Services</span></div><div id="sddwcc6C9EF9CE_DAEF_11D2_882B_006097B596A6" style="margin-top: 0px; margin-bottom: 0px; margin-left: 15px; display: block;" l="-1" epd="1"><div id="ddwcc5F0ED4A0_5FC5_4239_9876_5E9D9B468EC7" style="white-space: nowrap;" cptype="wgp" move="0" l="1" order="0"><img width="9" height="9" style="padding: 3px 1px 5px; cursor: default;" src="../../Images/Treeview/minus.gif" board="0" ct="pm"><img align="absmiddle" src="../../Images/Treeview/tvFolder.gif" border="0" hspace="3" ct="" eurl=""><span title="EMEA" style="cursor: pointer;">EMEA</span></div>
这是一个漫长的过程,我真的很想知道是否有人能够建议如何进行。如果需要更多信息,请告诉我。
关于, 斯拉瓦