Reputation: 450
Trying to automate filling in the input field for amazon seller central with AutoIT. Everything works great, but maybe the page loads to slow or something but the string I'm sending to the form input element is getting truncated. Here's my code:
#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("[email protected]")
Upvotes: 1
Views: 3287
Reputation: 795
You don't want to use the send function because it is not very reliable. Try _IEFormElementSetValue instead. Most of the IE functions have a built in load wait function so they won't execute the next line of code until the web page is loaded.
This code works for me:
#include <IE.au3>
;change this to your login info
login("[email protected]", "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
Upvotes: 2