作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
卡住 - 需要帮助!
我正在尝试在我们公司内部网站的 IE 网页中自动执行操作项目。我可以填写任何类型的文本对象 , 点击 提交按钮 等等,但有几个项目在 中。网格/表格(剑道网格)或 下拉列表。我似乎无法弄清楚如何从这些网格/表格或下拉列表中进行选择。
我已经尝试了我能想到的一切,但无济于事。我用过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
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>
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>
最佳答案
这是选择 kendoGrid 第一行的方法:
ie.Document.parentWindow.execScript "$('#drgdLease').data('kendoGrid').select('tr:eq(0)');"
'============================================================================================
' Module : <in any standard module>
' Version : 0.1
' Part : 1 of 1
' References : Microsoft Internet Controls [SHDocVw]
' Source : https://stackoverflow.com/a/46483783/1961728
'============================================================================================
' Required if late binding SHDocVw
Private Enum tagREADYSTATE
READYSTATE_UNINITIALIZED = 0
READYSTATE_LOADING
READYSTATE_LOADED
READYSTATE_INTERACTIVE
READYSTATE_COMPLETE
End Enum
Public Sub AutomateKendoUI()
' Create and use a new instance of IE
With New SHDocVw.InternetExplorer '##Late Binding: CreateObject("InternetExplorer.Application")
.Visible = True ' False is default
.Navigate "http://demos.telerik.com/kendo-ui/grid/index"
Do Until .Busy = False And .ReadyState = SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE: DoEvents: Loop '##Late Binding: = tagREADYSTATE.READYSTATE_COMPLETE ##No Enums: = 4
' Get and use the main DOM
With .Document
' Race Condition Work-Around
' Kendo UI may not have finished loading the Grid data before we invoke its select method.
' Therefore, we continue to invoke the method until a selected row is detected.
Do
.parentWindow.execScript "$('#grid').data('kendoGrid').select('tr:eq(0)');"
On Error Resume Next
Dim elm_tr As MSHTML.HTMLTableRow: Set elm_tr = .querySelector("#grid tr.k-state-selected")
On Error GoTo 0
Loop While elm_tr Is Nothing
End With
End With
End Sub
select
方法
1 :
Example - select the first and second table rows
...var grid = $("#grid").data("kendoGrid");
grid.select("tr:eq(1), tr:eq(2)");
:eq()
选择器
2 :
eq selector
Description: *Select the element at index
n
within the matched set.*
jQuery(":eq(index)")
index: Zero-based index of the element to match.
tbody
尽管
3 对象正确:
Example - get the first table row
...var grid = $("#grid").data("kendoGrid");
var row = grid.tbody.find("tr:eq(0)");
关于vba - 使用 Excel VBA 在 Kendo UI 小部件中选择/操作项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43127317/
我是一名优秀的程序员,十分优秀!