If text found execute group of commands, if text not found continue next commands

Hello,
I am searching some text in webpage (command line 4, 12, 21), if the text found a group of command will be execute (e.g. command line 6,7,8,9). If the text not found, search for next text in webpage and so on.


In my code commands are executing if text found or not.

need solution.

Thanks

What is the problem?

Need only an if command

Yes, If command needed. If text found then execute the group of commands associated with the text. If text not found search next text and if that found also execute that group of commands associated with the text. I need to search many text and for every text there is different commands.

{

“Name”: “TET”,
“CreationDate”: “2020-11-29”,
“Commands”: [
{
“Command”: “open”,
“Target”: “https://v2.gcchmc.org/book-appointment/”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorignore”
},

{
  "Command": "if_v2",
  "Target": "${!statusOK}",
  "Value": "false"
},
{
  "Command": "assertText",
  "Target": "xpath=/html/body/div[4]/div/div[2]/div/table[2]/tbody/tr[3]/td",
  "Value": "+8803172688"
},
{
  "Command": "else",
  "Target": "",
  "Value": ""
},
{
  "Command": "XClick",
  "Target": "GREEN_dpi_96.png",
  "Value": ""
},
{
  "Command": "pause",
  "Target": "1000",
  "Value": ""
},
{
  "Command": "XClick",
  "Target": "IMACROS_dpi_96.png",
  "Value": ""
},
{
  "Command": "pause",
  "Target": "1000",
  "Value": ""
},
{
  "Command": "XClick",
  "Target": "PLAY_dpi_96.png",
  "Value": ""
},
{
  "Command": "end",
  "Target": "",
  "Value": ""
},
{
  "Command": "if_v2",
  "Target": "${!statusOK}",
  "Value": "true"
},
{
  "Command": "assertText",
  "Target": "xpath=/html/body/div[4]/div/div[2]/div/table[2]/tbody/tr[3]/td",
  "Value": "+880316579190"
},
{
  "Command": "else",
  "Target": "",
  "Value": ""
},
{
  "Command": "XClick",
  "Target": "BLUE_dpi_96.png",
  "Value": ""
},
{
  "Command": "pause",
  "Target": "1000",
  "Value": ""
},
{
  "Command": "XClick",
  "Target": "IMACROS_dpi_96.png",
  "Value": ""
},
{
  "Command": "pause",
  "Target": "1000",
  "Value": ""
},
{
  "Command": "XClick",
  "Target": "PLAY_dpi_96.png",
  "Value": ""
},
{
  "Command": "end",
  "Target": "",
  "Value": ""
}

]
}

Those commands not working for me, text found or not executing all the commands.

Please give me if commands.
Thanks

The problem probably depends on the Xclick command because this command to work requires that in front of the screen you have exactly element to click otherwise it does not work.

So before using Xclick you need to make sure that on the screen you see the item to click otherwise Xclick does not work because it requires the focus on the screen.

If on the screen you have the browser I have another Xclick window not working.

Seems you want to start Imacros with this macro but is not possible because you have in front browser with ui vision and to start imacros you need to have in front browser with Imacros, you can try to add in your macro Xrun command to run browser with imacros before use Xclick and you must sure to have always element to click with Xclick in front of screen.

I have no problem with Xclick command, that is working fine because the target is on the screen.

Please give me an example of if command to search multiple text in single webpage.

For example: I am searching these three phone number +12545554, +12568455 and +12587745

If one of these three phone number is found in webpage my macro click a submit button, otherwise macro continue running and search for next phone number.

Please give me an example of if command for the condition.

There are a large amount to do this work in alternative mode.

I never used assertText command i do not know it

Your xpath can be dynamic in this case you need to find a better xpath.

Usually i use external tool to detect best xpath.

This seems a simple macro to do with storetext and if condition

I think you have explained the problem incorrectly, explain well what you need to do, add images, clarify well the work you have to do because I do not see on the page that you have indicated the data you want to extract.

I’ve created a new macro for demo:

{
“Name”: “NEW RECORD”,
“CreationDate”: “2020-11-30”,
“Commands”: [
{
“Command”: “open”,
“Target”: “If text found execute group of commands, if text not found continue next commands”,
“Value”: “”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “!errorignore”
},
{
“Command”: “store”,
“Target”: “true”,
“Value”: “{!statusOK}" }, { "Command": "if_v2", "Target": "{!statusOK}”,
“Value”: “true”
},
{
“Command”: “verifyText”,
“Target”: “xpath=//[@id=“post_5”]/div/div[2]/div[2]/div/p[3]",
“Value”: “+12545554”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “open”,
“Target”: “https://google.com”,
“Value”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “if_v2”,
“Target”: “${!statusOK}”,
“Value”: “true”
},
{
“Command”: “verifyText”,
“Target”: "xpath=//
[@id=“post_5”]/div/div[2]/div[2]/div/p[3]”,
“Value”: “+125684550”
},
{
“Command”: “else”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “open”,
“Target”: “https://msn.com”,
“Value”: “”
},
{
“Command”: “end”,
“Target”: “”,
“Value”: “”
}
]
}

Here is my condition:

If any one number matches it should open urls.

(if match with the number +12545554 open https://google.com , if match with the number +12568455, open https://msn.com)

But here my script does not act as my condition. The number +12545554 matches but do not open google.com Only open msn.com if the text does not match.

Please give solution.

For example: I am searching these three phone number +12545554, +12568455 and +12587745

If one of these three phone number is found in webpage my macro click a submit button, otherwise macro continue running and search for next phone number.

Your macro looks almost good. I think the the issue is that you need set !statusOK (back) to true before every new verify… check. Otherwise **it always stays “false”. So even if the next command is ok again, !statusOk would remain be false. It need to be “manually” reset:

To reset !statusOK, just add

store | true | !statusOk before each verify…

By the way: With verify… commands you do not need to set !ERRORIGNORE to true. Verify…commands only trigger a warning. Only Assert… commands stop the macro.

Please give me a solution… my code not working… Not opening the URL even text is matched … :frowning:
It’s important for me. :frowning:

{
  "Name": "NEW RECORD",
  "CreationDate": "2020-11-30",
  "Commands": [
    {
      "Command": "open",
      "Target": "https://forum.ui.vision/t/if-text-found-execute-group-of-commands-if-text-not-found-continue-next-commands/6568/3",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!statusOk"
    },
    {
      "Command": "if_v2",
      "Target": "${!statusOK}",
      "Value": ""
    },
    {
      "Command": "verifyText",
      "Target": "xpath=//*[@id=\"post_5\"]/div/div[2]/div[2]/div/p[3]",
      "Value": "For example: I am searching these three phone number +12545554, +12568455 and +12587745"
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://google.com",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!statusOk"
    },
    {
      "Command": "if_v2",
      "Target": "${!statusOK}",
      "Value": ""
    },
    {
      "Command": "verifyText",
      "Target": "xpath=//*[@id=\"post_5\"]/div/div[2]/div[2]/div/p[3]",
      "Value": "For example: I am searching these three phone number +12545554, +12568455 and +12587745"
    },
    {
      "Command": "else",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://msn.com",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}

Explain well what you need to do add images and I’ll create you a much more efficient macro code that works without using the commands you’re using.

There are several solutions to do a job, some are better than the ones you’re using.

I simplified my things… Please have a look.

  1. open
    http://cartlidgesqualitymeats.com/

  2. Search for text “Cartlidges Quality Meats”
    –> if text found, go “https://google.com
    –> if text not found, go for next text search.

  3. Search for text “609-396-3966”
    –> if text found, go to “https://msn.com
    –> if text not found, continue process.

Solve with this code, i have few time but can be create in better way this is the fast and easy way to create e multiple condition search

Do exactly the work you need, with more time this can be creaetd with few code line with times command and array, will be more short the macro code and more fast but require more time to write a macro code.

{
  "Name": "aaaaaaaaaaaaa",
  "CreationDate": "2020-11-30",
  "Commands": [
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore"
    },
    {
      "Command": "bringBrowserToForeground",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "First Research",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "http://cartlidgesqualitymeats.com/",
      "Value": ""
    },
    {
      "Command": "pause",
      "Target": "5000",
      "Value": ""
    },
    {
      "Command": "storeText",
      "Target": "xpath=//h1[contains(.,'Cartlidges Quality Meats')]",
      "Value": "Result"
    },
    {
      "Command": "echo",
      "Target": "${Result}",
      "Value": "#shownotification"
    },
    {
      "Command": "if_v2",
      "Target": "${Result} == \"Cartlidges Quality Meats\"",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://google.com",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Url Opened",
      "Value": "#shownotification"
    },
    {
      "Command": "pause",
      "Target": "10000",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "if_v2",
      "Target": "${Result} != \"Cartlidges Quality Meats\"",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Text Cartlidges Quality Meats Not Found",
      "Value": "#shownotification"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "comment",
      "Target": "Second Research",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "http://cartlidgesqualitymeats.com/",
      "Value": ""
    },
    {
      "Command": "pause",
      "Target": "5000",
      "Value": ""
    },
    {
      "Command": "storeText",
      "Target": "xpath=//h1[contains(.,'609-396-396')]",
      "Value": "Result"
    },
    {
      "Command": "echo",
      "Target": "${Result}",
      "Value": "#shownotification"
    },
    {
      "Command": "if_v2",
      "Target": "${Result} == \"609-396-396\"",
      "Value": ""
    },
    {
      "Command": "open",
      "Target": "https://msn.com",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "Url Opened",
      "Value": "#shownotification"
    },
    {
      "Command": "pause",
      "Target": "10000",
      "Value": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "if_v2",
      "Target": "${Result} != \"609-396-396\"",
      "Value": ""
    },
    {
      "Command": "echo",
      "Target": "609-396-396 Not Found",
      "Value": "#shownotification"
    },
    {
      "Command": "end",
      "Target": "",
      "Value": ""
    }
  ]
}
1 Like

BIG THANKS!!
Its exactly what I need. :+1:

It is working perfect for me. But as you told me that this can be created with few code, I’ll be very glad if you do it obviously in your free time.

Thank you once again bro…

1 Like

What is the problem?