Search code examples
javascriptxmlxpathimacros

iMacros - XPATH - Compare text XPATH with text reference


Using iMacros, I want to read the text of an XPATH. If the text read matches the expected, continue to run the task. If the read text of the XPATH does not match the expected text, reread it (looped, until it matches the expected one).

I have managed to read the XPATH text, extract the text and save it in a txt. But it's not what I'm looking for. The idea is the following: Example: Textreference = "New Message" Textoxpath = "" // Initialization to 0, for example

If (textoreferencia == textoxpath) Execute code and exit Else Read xpath again

I've thought about creating a variable with the reference text. Create another variable with the XPATH text, and compare these two variables. But I do not know how to write that code on xpath.

EDIT WITH CODE: I have:

URL GOTO=https://www.google.es SET !VAR1 1 SET !EXTRACT_TEST_POPUP NO TAG XPATH="//div[@id='tabmbTab1']" EXTRACT=TXT SAVEAS TYPE=EXTRACT FOLDER=C:\Users\F17MC\Desktop FILE=extraction.txt


Solution

  • I suggest trying this way:

    URL GOTO=https://www.google.es
    SET !EXTRACT_TEST_POPUP NO
    SET textoreferencia "The expected text"
    
    ' let's wait until the expected text appears (e.g. one day) '
    SET !TIMEOUT_STEP 86400
    TAG XPATH="//div[@id='tabmbTab1'][text()='{{textoreferencia}}']" EXTRACT=TXT
    ' restoring the default value '
    SET !TIMEOUT_STEP 6
    
    ' ...