使用AutoIT填写表单输入字段

时间:2015-11-24 20:57:59

标签: forms internet-explorer automation 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") 

1 个答案:

答案 0 :(得分:2)

您不想使用send函数,因为它不太可靠。请尝试使用_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