iMacro 查找元素

iMacro Finding an Element

本文关键字:元素 查找 iMacro      更新时间:2023-10-16

我正在编写一个C++的iMacro脚本,该脚本将登录到网站,转到特定页面并查找复选框。如果该复选框不存在,则脚本将每 X 秒刷新一次页面。如果该复选框确实存在,那么它将选中它。基本上,我只需要弄清楚如何让iMacro搜索复选框。这是我到目前为止的代码:

using namespace System;
#include <string>
int timeout = 60;
ref class ManagedGlobals {
public:
    static iMacros::AppClass^ app;
};
// test if element exists
bool doesElementExist() {
    iMacros::Status stat;
    ManagedGlobals::app->iimDisplay("Searching for element", timeout);
    stat = ManagedGlobals::app->iimPlay("CODE:SET !TIMEOUT_TAG 1n"
        + "CODE:TAG POS=8 TYPE=INPUT:CHECKBOX FORM=ACTION:/pls/PROD/bwykfreg.P_AltPin1?deviceType=C ATTR=NAME:sel_crn EXTRACT=TXT", timeout);
    ManagedGlobals::app->iimDisplay(stat.ToString(), timeout);
    ManagedGlobals::app->iimPlay("CODE:WAIT SECONDS=10", timeout);
    if (stat != iMacros::Status::sOk) {
        ManagedGlobals::app->iimDisplay("Didn't find it", timeout);
        return false;
    }
    ManagedGlobals::app->iimDisplay("Found it", timeout);
    return true;
}

我已经在页面上对此进行了测试,复选框确实存在,但脚本找不到它,而是返回错误代码 -1100,根据此页面,这意味着Load Failed: Failed to load the macro (syntax or I/O error) (Found wrong macro command while loading file).

有人知道问题是什么吗?

尝试删除此部分。

FORM=ACTION:/pls/PROD/bwykfreg.P_AltPin1?deviceType=C

此部分可以在页面上更改,但 TAG 不需要它来查找元素。还尝试通过更改POS = 8来更改复选框的位置。从数字 1 开始到 15,看看这个数字是否也会改变。

此外,您可能还想更改此设置

stat = ManagedGlobals::app->iimPlay("CODE:SET !TIMEOUT_TAG 1n"
        + "CODE:TAG POS=8 TYPE=INPUT:CHECKBOX FORM=ACTION:/pls/PROD/bwykfreg.P_AltPin1?deviceType=C ATTR=NAME:sel_crn EXTRACT=TXT", timeout);

进入这个

stat = ManagedGlobals::app->iimPlay("CODE:SET !TIMEOUT_TAG 1n"
        + "TAG POS=8 TYPE=INPUT:CHECKBOX ATTR=NAME:sel_crn EXTRACT=TXT", timeout);

代码:在一个宏中只能出现一次。 n用于拆分命令行。