查找并使用AutoHotKey填写输入字段 [英] Find and fill an input field with AutoHotKey

查看:967
本文介绍了查找并使用AutoHotKey填写输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您对所有AutoHotKey大师的挑战:

A challenge to all you AutoHotKey masters:

给我们一个函数,该函数将查找并移动光标到输入字段(例如LoginName),或者发送输入文本.对于像我这样的老懒惰黑客,他们只是喜欢AHK,它看起来像这样:

Give us a function that will Find and Move the Cursor to an Input Field (E.g. LoginName) and, alternatively send input text. For the old, lazy hackers like myself just fiddling with AHK, it would look like this:

FindFillField(*elementid*,*sendtext*,*alt-text*)

其中elementid是该字段的HTML ID,例如用户名, 其中sendtext是要填充的文本, 其中alt-text可以是附加的特定文本,以帮助识别字段.

Where elementid is the HTML id for the field, e.g. USERNAME, where sendtext is the text to fill and where alt-text could be additional, specific text to help identify the fields.

附加的可选参数总是有助于消除奇数情况,让您的想像力发疯!

Additional, optional parameters are always helpful to round out odd cases so let your imaginations run wild!

对于像我这样的老朋友和任何人,这将是创建简单的登录宏的祝福.

For old-timers like me, and for anyone, this would be a blessing in creating simple login macros.

推荐答案

您可以使用以下代码将文本发送到输入字段:

You can send text to an input field with the following code:

wb.document.getElementById("login-username").value := "myUserName"

其中wb是COM对象,login-username是输入字段的ID,而myUserName是您要输入的内容.

Where wb is the COM object, login-username is the ID of the input field, and myUserName is what you wish to input.

装有ID的用户,还可以按名称getElementsByName(...),标签名称getElementsByTagName(...)或类名称getElementsByClassName(...)查找输入字段.我发现了本教程有用.使用Chrome或Firefox查找如何识别输入字段(右键单击并按检查元素").

Insted of ID, you can also find the input field by name getElementsByName(...), tag name getElementsByTagName(...) or class name getElementsByClassName(...). I've found this tutorial to be useful. Use Chrome or Firefox to find out how to identify the input field (rightclick and press "inspect element").

如果要将光标移动到输入字段,请使用

If you want to move the cursor to the input field, use

wb.document.getElementById("login-username").focus()

这是使用IE和Stack Overflow登录页面的完整示例:

Here is a full example, using IE and the Stack Overflow login page:

; Create IE instance
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := True
wb.Navigate("https://stackoverflow.com/users/login")
; Wait for page to load:
While wb.Busy or wb.ReadyState != 4
    Sleep, 100
; Press "Log in using Stack Exchange"
wb.document.getElementById("se-signup-legend").click()
While wb.Busy or wb.ReadyState != 4
    Sleep, 100
; EITHER focus on the input field:
wb.document.getElementsByName("email")[0].focus()
; OR send text directly to the field:
wb.document.getElementsByName("email")[0].value := "my@email.com"

这篇关于查找并使用AutoHotKey填写输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆