使用 AutoIT 填写表单输入字段

Filling form input field with AutoIT

尝试使用 AutoIT 自动填写亚马逊卖家中心的输入字段。一切正常,但也许页面加载速度变慢或其他原因,但我发送到表单输入元素的字符串被截断了。这是我的代码:

#include <IE.au3>



$oIE = _IECreate()
_IENavigate($oIE, "https://sellercentral.amazon.com/hz/home")
Local $oAddress = _IEPropertyGet($oIE, "locationurl")
ConsoleWrite($oAddress & @CRLF)
$oSignin = "https://sellercentral.amazon.com/gp/sign-in/sign-in.html?destination=https%3A%2F%2Fsellercentral.amazon.com%2Fhz%2Fhome"
if $oAddress = $oSignin Then
ConsoleWrite("Sucess! Connected!" & @CRLF)
Else
    ConsoleWrite("You are not on the sign in page")
EndIf
_IELoadWait($oIE)
Local $oForm = _IEFormGetObjByName($oIE, "signinWidget")
Local $oInputFile = _IEFormElementGetObjByName($oForm, "username")

; Assign input focus to the field and then send the text string
_IEAction($oInputFile, "focus")

; Select exisiting content so it will be overwritten

_IEAction($oInputFile, "selectall")


Send("12345678@asdfasdfdasfasd.com") 

您不想使用发送功能,因为它不太可靠。请改用 _IEFormElementSetValue。大多数 IE 函数都有一个内置的加载等待函数,因此在网页加载完成之前它们不会执行下一行代码。

这段代码对我有用:

#include <IE.au3>

;change this to your login info
login("12345@gmail.com", "FakePass")

Func login($sUserName, $UserPass)
    Local $oIE, $sSignin, $sAddress, $oForm, $oUserInput, $oUserPassInput

    $oIE = _IECreate("https://sellercentral.amazon.com/hz/home")

    $sAddress = _IEPropertyGet($oIE, "locationurl")
    ConsoleWrite($sAddress & @CRLF)

    $sSignin = "https://sellercentral.amazon.com/gp/sign-in/sign-in.html?destination=https%3A%2F%2Fsellercentral.amazon.com%2Fhz%2Fhome"
    If $sAddress = $sSignin Then
        ConsoleWrite("Sucess! On sign in page!" & @CRLF)
    Else
        ConsoleWrite("You are not on the sign in page" & @CRLF)
        Return
    EndIf

    $oForm = _IEFormGetObjByName($oIE, "signinWidget")
    $oUserInput = _IEFormElementGetObjByName($oForm, "username")
    $oUserPassInput = _IEFormElementGetObjByName($oForm, "password")

    ;set user name
    _IEFormElementSetValue($oUserInput, $sUserName)

    ;set pass
    _IEFormElementSetValue($oUserPassInput, $UserPass)

    _IEFormSubmit($oForm)
EndFunc   ;==>login