0

我的这个 Autoit 脚本运行良好,但是如何让它重复工作而不重复为每个值键入脚本?

Value1 = usernameA 与 passwordA 一起使用

Value2 = usernameB 与 passwordB 一起使用

Value3 = usernameC 与 passwordB 一起使用

#include <IE.au3>
$oIE = _IECreate ("www.site.com/login")

$username = _IEGetObjByName ($oIE, "q_username")
$id = _IEGetObjByName ($oIE, "q_username")
$password = _IEGetObjByName ($oIE, "q_password")
$id = _IEGetObjByName ($oIE, "q_password")
$button1 =  _IEGetObjByName ($oIE, "login")

_IEPropertySet($username, 'innerText', 'usernameA')
_IEPropertySet($id, 'innerText', 'usernameA')
_IEPropertySet($Password, 'innerText', 'passwordA')
_IEPropertySet($id, 'innerText', 'passwordA')
_IEAction ($button1,"click")

我不希望它变成这样!

#include <IE.au3>

$oIE = _IECreate ("www.site.com/login")
$username = _IEGetObjByName ($oIE, "q_username")
$id = _IEGetObjByName ($oIE, "q_username")
$password = _IEGetObjByName ($oIE, "q_password")
$id = _IEGetObjByName ($oIE, "q_password")
$button1 =  _IEGetObjByName ($oIE, "login")

_IEPropertySet($username, 'innerText', 'usernamea')
_IEPropertySet($id, 'innerText', 'usernameA')
_IEPropertySet($Password, 'innerText', 'passworA')
_IEPropertySet($id, 'innerText', 'passwordA')
_IEAction ($button1,"click")

$oIE = _IECreate ("www.site.com/login")
$username = _IEGetObjByName ($oIE, "q_username")
$id = _IEGetObjByName ($oIE, "q_username")
$password = _IEGetObjByName ($oIE, "q_password")
$id = _IEGetObjByName ($oIE, "q_password")
$button1 =  _IEGetObjByName ($oIE, "login")

_IEPropertySet($username, 'innerText', 'usernameB')
_IEPropertySet($id, 'innerText', 'usernameB')
_IEPropertySet($Password, 'innerText', 'passwordB')
_IEPropertySet($id, 'innerText', 'passwordB')
_IEAction ($button1,"click")

$oIE = _IECreate ("www.site.com/login")
$username = _IEGetObjByName ($oIE, "q_username")
$id = _IEGetObjByName ($oIE, "j_username")
$password = _IEGetObjByName ($oIE, "q_password")
$id = _IEGetObjByName ($oIE, "q_password")
$button1 =  _IEGetObjByName ($oIE, "login")

_IEPropertySet($username, 'innerText', 'usernameC')
_IEPropertySet($id, 'innerText', 'usernameC')
_IEPropertySet($Password, 'innerText', 'passwordC')
_IEPropertySet($id, 'innerText', 'passwordC')
_IEAction ($button1,"click")

另外,当它完成时如何让它回到脚本的第一行?

4

1 回答 1

0

使用函数:

#include <IE.au3>

Func TestPassword($user, $pass)
    $oIE = _IECreate ("www.site.com/login")

    $username = _IEGetObjByName ($oIE, "q_username")
    $id = _IEGetObjByName ($oIE, "q_username")
    $password = _IEGetObjByName ($oIE, "q_password")
    $id = _IEGetObjByName ($oIE, "q_password")
    $button1 =  _IEGetObjByName ($oIE, "login")

    _IEPropertySet($username, 'innerText', $user)
    _IEPropertySet($id, 'innerText', $user)
    _IEPropertySet($Password, 'innerText', $pass)
    _IEPropertySet($id, 'innerText', $pass)

    _IEAction ($button1,"click")
EndFunc


TestPassword('usernameA', 'passwordA');
TestPassword('usernameB', 'passwordB');
TestPassword('usernameC', 'passwordC');

您甚至可以创建一个数组并使用以下命令对其进行迭代For...In...

$credentials[0]['user'] = 'usernameA';
$credentials[0]['pass'] = 'passwordA';
$credentials[1]['user'] = 'usernameB';
$credentials[1]['pass'] = 'passwordB';

For $cred In $credentials
    TestPassword($cred['user'], $cred['pass']);
Next
于 2013-08-05T15:50:04.247 回答