【发布时间】:2017-03-30 20:02:38
【问题描述】:
卡住了 - 需要帮助!
我正在尝试在我们公司内部网站的 IE 网页中自动执行操作项。我可以填写任何类型的文本对象,点击提交按钮等,但有几个项目要么在网格/表格中(剑道Grid) 或 下拉列表 列表。我似乎不知道如何从这些网格/表格或下拉列表中进行选择。
我已经尝试了我能想到的一切,但无济于事。我用过getElementById()、getElementsByTagName()、getElementsByName(),甚至还有一些网页抓取技术。
很遗憾,由于该网页位于内部站点上,其他人无法对其进行测试。
这是我的代码的主要部分
'After opening the web page, inserting a number, selecting the "search"
' (all from the VBA script), I have to use a "mousemove", "mousedown" and
' "mouseup" to select the item, whick is what the "myClick" subroutine does
myClick '<<< THIS IS WHAT I WANT TO GET RID OF >>>
'I left the following segment in to show that I'm able to do several other functions
myDocs = ie.Document.getElementById("DispatchComments").Value
If myInfo = True Then
ie.Document.getElementById("DispatchComments").Value = "__" & myCell5 & "__" & myDocs
Else: End If
'IF ESTIMATED TIME IS LESS THAN 0, ENTER 120 - Enter estimated time
If ie.Document.getElementById("TotalEstimatedTime").Value < 10 Then
ie.Document.getElementById("TotalEstimatedTime").Value = 120
Else: End If
End With
End Sub
`
这是一个screen shot,在输入租约号并单击搜索按钮后。我设法选择该行的唯一方法是以编程方式在所示的三个白色背景区域之一中单击鼠标。我的代码使用mousemove 和坐标来选择行,向下滚动到一个坦克下拉菜单并单击它打开,这样我就可以手动选择一个坦克编号。
这部分代码是我卡住的地方
Set myChoice1 = ie.Document.getElementById("drgdLease").getElementsByTagName("tr")(1)
With myChoice1
.getElementsByTagName("td")(0).Focus '<<---Works all the way to here
.FireEvent ("onmouseover") '<<---No errors from this point on
.FireEvent ("onmousedown") 'but doesn't do anything
.FireEvent ("onmouseup")
.FireEvent ("onclick") '<<---some other things tried
.FireEvent ("ondblclick")
.FireEvent ("onselect")
td.innerText = value
td.innerHTML = value
End With
'<tr role="row" data-uid="db62d811-4337-477c-a0fd-0e9e036670bb">
' <td role="gridcell">998262</td> '<<---This is the info/row I need to select
' <td role="gridcell">HENDERSON (SMACKOVER) STORAGE</td>
' <td role="gridcell">ORYAN OIL & GAS</td>
检查我尝试选择的区域的元素会显示此 HTML
name="Result">
<div class="k-widget k-grid" id="drgdLease" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="grid">
<table class="k-selectable" role="grid" style="-ms-touch-action: double-tap-zoom pinch-zoom;" data-role="selectable">
<colgroup>
<col>
<col>
<col>
</colgroup>
<thead class="k-grid-header" role="rowgroup">
<tr role="row">
<th class="k-header k-with-icon" scope="col" data-title="Lease Number" data-index="0" data-field="LeaseCode" data-role="columnsorter">
<a tabindex="-1" class="k-header-column-menu" href="#">
<span class="k-icon k-i-arrowhead-s"></span>
</a>
<a class="k-link" href="/LeaseProfiles/GetLeasesSearch?Length=9&drgdLease-sort=LeaseCode-asc">Lease Number</a>
</th>
<th class="k-header k-with-icon" scope="col" data-title="Lease Name" data-index="1" data-field="LeaseName" data-role="columnsorter">
<a tabindex="-1" class="k-header-column-menu" href="#">
<span class="k-icon k-i-arrowhead-s"></span>
</a>
<a class="k-link" href="/LeaseProfiles/GetLeasesSearch?Length=9&drgdLease-sort=LeaseName-asc">Lease Name</a>
</th>
<th class="k-header k-with-icon" scope="col" data-title="Lease Operator" data-index="2" data-field="LeaseOperator.OperatorName" data-role="columnsorter">
<a tabindex="-1" class="k-header-column-menu" href="#">
<span class="k-icon k-i-arrowhead-s"></span>
</a>
<a class="k-link" href="/LeaseProfiles/GetLeasesSearch?Length=9&drgdLease-sort=LeaseOperator.OperatorName-asc">Lease Operator</a>
</th>
</tr>
</thead>
<!--
This is what the code looks like before selecting the item.
ie: before clicking anywhere on the row.
-->
<tbody role="rowgroup">
<tr role="row" data-uid="db62d811-4337-477c-a0fd-0e9e036670bb">
<td role="gridcell">998262</td>
<td role="gridcell">HENDERSON (SMACKOVER) STORAGE</td>
<td role="gridcell">ORYAN OIL & GAS</td>
</tr>
</tbody>
</table>
<!--
This is what the code changes to after clicking the row.
Note the class and arial are added on the `tr role` line, which may be binding the data.
-->
<tr role="row" data-uid="db62d811-4337-477c-a0fd-0e9e036670bb" class = "k-state- selected" arial = "true">
<td role="gridcell">998262</td>
<td role="gridcell">HENDERSON (SMACKOVER) STORAGE</td>
<td role="gridcell">ORYAN OIL & GAS</td>
【问题讨论】:
-
如果你注释掉
On Error Resume Next,你会得到错误,在哪一行? -
我只是按“原样”在代码上试了一下,没有出现任何错误。
-
之前的代码 sn-p 是一团糟。我重做了它以使其更易于阅读和理解。
-
也许有人可以给我一个 javascript 解决方案,或者至少 something 来尝试。我已经尝试了所有我能想到或在这个网站和其他网站上找到的东西。 米奇
-
此页面是否与您尝试自动化的页面相似? .....demos.telerik.com/kendo-ui/grid/index
标签: vba excel internet-explorer kendo-ui