Pergunta

So I'm using iMacros and I will use a JS file to play my macro based on a few if statements.

Here's a small sample pseudocode:

if (TextContent == "Hello World")
{
    iim.Play("myMacro.iim);
}

I'm trying to check if the webpage contains the word "Hello World!".

I heard about the TextContent method but I don't know how to use. Is it the proper way to use it? If not then how do you use it properly?

UPDATE

I've tried the ones but it's giving me a reference error.

Foi útil?

Solução

This code is totally wrong if you want to run it in iMacros

if (TextContent == "Hello World")
{
    iim.Play("myMacro.iim);
}

This code is CORRECT.

var macro;

macro ="CODE:";
macro +="SET !ERRORIGNORE YES"+"\n";
macro +="TAG POS=1 TYPE=HTML ATTR=TXT:* EXTRACT=TXT"+"\n";

iimPlay(macro)

var text=iimGetLastExtract();

if(text.search("Hello World")!=-1)
{
    alert("Found the text");
}

This will extract all text from the page and if there is Hello World in it, it will alert "Found the text". Also there are tons of examples on how to make iMacros JavaScript script.

Here is one on the link

Also you can't use JavaScript code in iMacros just like that. If you use

document.getElelementById("some_id").click();

just like this in the script it will not work.

But if you use it as a part of URL GOTO command it might work in IE and earlier versions of Firefox.

URL GOTO=javascript:document.getElelementById("some_id").click();

The rule is

  1. First extract with iMacros TAG command
  2. Store the text in variable with iimGetLastExtract()
  3. Use search(), match(), indexOf() method to find what you are looking for.

Outras dicas

textContent is property of documentElement so you need to:

if ((document.documentElement.textContent || document.documentElement.innerText).indexOf('Hello World') > -1)
{
    iim.Play("myMacro.iim);
}

Or as suggested in comment use jQuery's text() method which is cross-browser compatible

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top