Replace StoreText variable with 0 if not found

Morning All

in the below macro, at the storetext portion, I would like it to be able to set the value to be 0 if the element does not exist. is this capable with a if and potentially another command?


{
  "Name": "Team Emails",
  "CreationDate": "2022-2-10",
  "Commands": [
    {
      "Command": "csvRead",
      "Target": "emails.csv",
      "Value": "",
      "Description": "xero"
    },
    {
      "Command": "store",
      "Target": "true",
      "Value": "!errorignore",
      "Description": "reconcile"
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (1)",
      "Value": "currentRow",
      "Description": "reconcile"
    },
    {
      "Command": "while_v2",
      "Target": "${currentRow} <= ${!CSVREADMAXROW}",
      "Value": "currentRow",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "${currentRow}",
      "Value": "!CSVREADLINENUMBER",
      "Description": ""
    },
    {
      "Command": "csvRead",
      "Target": "emails.csv",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": " ${!COL1}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "15",
      "Value": "!timeout_wait",
      "Description": ""
    },
    {
      "Command": "visualVerify",
      "Target": "emailloaded_dpi_96.png",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "type",
      "Target": "/html/body/div[7]/div[2]/div/div[1]/div[3]/header/div[2]/div[2]/div[2]/form/div/input",
      "Value": "label:Inbox older_than:1d ",
      "Description": ""
    },
    {
      "Command": "XType",
      "Target": "${KEY_ENTER}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "visualVerify",
      "Target": "teams1_dpi_87.png",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "XClick",
      "Target": "/html/body/div[7]/div[2]/div/div[2]/div[1]/div[2]/div/div/div/div/div[1]/div/div[2]/div[2]/div/span/div[1]",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "verifyElementPresent",
      "Target": "/html/body/div[7]/div[2]/div/div[2]/div[1]/div[2]/div/div/div/div/div[1]/div/div[2]/div[2]/div/span/div[1]/span/span[2]",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "if_v2",
      "Target": "${!LastCommandOk} == true",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "storeText",
      "Target": "/html/body/div[7]/div[2]/div/div[2]/div[1]/div[2]/div/div/div/div/div[1]/div/div[2]/div[2]/div/span/div[1]/span/span[2]",
      "Value": " ${!COL2}",
      "Description": ""
    },
    {
      "Command": "else",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "storeValue",
      "Target": "0",
      "Value": " ${!COL2}",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "executeScript_Sandbox",
      "Target": "return Number (${!CSVREADLINENUMBER}) +1;",
      "Value": "currentRow",
      "Description": ""
    },
    {
      "Command": "end",
      "Target": "",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "open",
      "Target": "https://mail.google.com/mail/u/0/#inbox?compose=new",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "store",
      "Target": "30",
      "Value": "!timeout_wait",
      "Description": ""
    },
    {
      "Command": "visualSearch",
      "Target": "email2_dpi_96.png",
      "Value": "emailavailable",
      "Description": ""
    },
    {
      "Command": "XType",
      "Target": "Angelique@cfo360.co.za${KEY_ENTER}nhlaka@nimbleaccounting.co.uk${KEY_ENTER}montaque@cfo360.co.za${KEY_ENTER}${KEY_TAB}Email Update${KEY_TAB}",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "pause",
      "Target": "1000",
      "Value": "",
      "Description": ""
    },
    {
      "Command": "XType",
      "Target": "Good Morning there are currently the following emails potentially still in progress: ${KEY_CTRL}${KEY_ENTER}Team Ziyaad-${teamziyaad}${KEY_CTRL}${KEY_ENTER}Team Yolandi-${teamyolandi}${KEY_CTRL}${KEY_ENTER}Team Ricardo-${teamricardo}${KEY_CTRL}${KEY_ENTER}Team Tebello-${teamtebello}${KEY_CTRL}${KEY_ENTER}Team Maneesha-${teamManeesha}${KEY_CTRL}${KEY_ENTER}Team Andrea-${teamAndrea}${KEY_CTRL}${KEY_ENTER}Tax Team-${teamTax}${KEY_CTRL}${KEY_ENTER}Onboarding-${Onboardings}${KEY_CTRL}${KEY_ENTER}${KEY_ENTER}This is all the emails which are not archived and are older than one day. Many means greater than 50${KEY_TAB}${KEY_ENTER}",
      "Value": "",
      "Description": ""
    }
  ]
}

You can check the !statusOK variable after storeText. If storeText failed (xpath not found) then !statusOK will be “false”. If so, then set the result to 0:

  • store | !statusOK | true

  • storeText | xpath=........

  • if ${!statusOK} == false
    store | 0 | ${!COL2}
    end

2 Likes

This is the way … XD @ulrich
#mandalorian

1 Like

Thanks, this did work after combining it with a few if_v2 statements to check if one or another element exists first.