如何定位除 id、class 或屏幕位置以外的表单元素?

How to target form elements other than by id, class or screen location?

我正在尝试使用 Internet Explorer 填写表格。该网页不包含 ID 或 class 名称。所以目前我将鼠标移动到基于屏幕大小的相对位置。但是这种屏幕分辨率依赖性是不需要的。

鉴于网页(内部网站)缺少 classes/ids,如何定位其 HTML 表单输入、文本区域、组合框、下拉菜单、日期选择器和屏幕以外的按钮位置?

您可以迭代所有 input 元素以确定您需要的元素:

#include <IE.au3>
$oIE = _IECreate("http://www.google.com")
$oAs = _IETagnameGetCollection($oIE, "input")
$i = 1
For $oA In $oAs
   _IEPropertySet($oA, "innertext", $i)
   $i = $i + 1
Next  

接下来您可以使用 $i 变量来设置正确的值。在此示例中,Google 搜索字段是第四个 input 元素,因此您可以这样填写:

#include <IE.au3>
$oIE = _IECreate("http://www.google.com")
$oAs = _IETagnameGetCollection($oIE, "input")
$i = 1
For $oA In $oAs
   If $i = 4 Then _IEPropertySet($oA, "innertext", "MyValue")
   $i = $i + 1
Next