Search code examples
javascriptif-statementimacros

imacros - ignore code if tag not found


URL GOTO=my site
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:login ATTR=NAME:name CONTENT=name
SET !ENCRYPTION NO
TAG POS=1 TYPE=INPUT:PASSWORD FORM=NAME:login ATTR=NAME:password CONTENT=pass
TAG POS=1 TYPE=BUTTON FORM=NAME:login ATTR=ID:s1
WAIT SECONDS=3
ONDOWNLOAD FOLDER=* FILE=image.jpg WAIT=YES
TAG POS=1 TYPE=IMG ATTR=HREF:*captcha* CONTENT=EVENT:SAVEPICTUREAS
WAIT SECONDS=3
TAB OPEN
TAB T=2
SET !EXTRACT_TEST_POPUP NO
URL GOTO=site of service
WAIT SECONDS=3
TAG POS=1 TYPE=INPUT:TEXT FORM=... ATTR=NAME:username CONTENT=...
TAG POS=1 TYPE=INPUT:TEXT FORM=ACTION:... ATTR=NAME:password CONTENT=...
TAG POS=1 TYPE=INPUT:FILE FORM=ACTION:... ATTR=NAME:pict CONTENT=image.jpg
TAG POS=1 TYPE=INPUT:SUBMIT FORM=ACTION:... ATTR=VALUE:Send
WAIT SECONDS=3
TAG POS=6 TYPE=TD ATTR=* EXTRACT=TXT
SET !CLIPBOARD {{!EXTRACT}}
tab close
TAB T=1
TAG POS=1 TYPE=INPUT:TEXT FORM=NAME:login ATTR=ID:recaptcha_response_field CONTENT={{!CLIPBOARD}}
TAG POS=1 TYPE=BUTTON FORM=NAME:login ATTR=ID:s1
WAIT SECONDS=3

I use this code to solve the CAPTCHA ..

Sometimes there is no CAPTCHA ..

I want to make this code only works if there is CAPTCHA ..

In the case of non-appearance of CAPTCHA (or image to save) ignores the following lines ..

I heard that this is possible through Javascript ..

But I can not find a way to do that ..

Any Help? ..


Solution

  • Yes, you can use JavaScript.

    Basically, what you need to do is check whether the captcha field do exists or not. Maybe something like this one.

    function isCaptchaExists() {
        var macro = "TAG POS=1 TYPE=IMG ATTR=HREF:*captcha* EXTRACT=HTM";
        var retcode = iimPlayCode(macro);
    
        return retcode < 0;
    }