Combined/nested variables not saving to csv

I have a loop running that scrapes image url’s and saves them in the format of image_src_1, image_src_2, etc.

Inside UI Vision the url’s show up, however when I export to the csv it displays ${image_src_x} not the actual url

I’m guessing it’s a syntax thing that I’m missing since I am nesting variables but not sure.

I am not sure if this is the reason, but While_v2 needs to be closed with END, and not endWhile. (endWhile is deprecated, now END is used).

1 Like

@admin
Add in the ui vision window the deprecated note to prevent the endWhile command from still being used for While_v2.

@ulrich
Thanks I didn’t know that the endWhile command is no longer used and it should be replaced with End I thought End was only used to close the If_v2.

@newuserkantu Using “endWhile” does not hurt - but we will probably remove all deprecated commands from the command dropdown with the next update. It is too confusing. Existing macros will not be affected by this change.

@ilyafish “Nested variables” (variables inside variables) are not supported. But you also do not need them. Usually arrays are a good replacement. If you tell me what you want to achieve, I can suggest a workaround.

@admin I am looking to save the image urls from a gallery to a csv line.

The idea was a loop that essentially does this:
(Lets say we are looking at the 3rd image in a gallery of 27)

  1. Grabs current image source url
  2. Grabs current image number (3)
  3. Saves it to the csv
  4. Returns current image number (3) and sets it as last image saved
  5. Clicks “next” and loops as long as last image saved isn’t equal to total image count - in this case once last image saved is 27, that would satisfy the “While_v2” condition and then continue

Ultimately all these url’s would be for a json feed to a website to populate our own gallery, so an array of urls should be sufficient

Post complete code of macro and complete log of ui vision please

@newuserkantu

Below is the code and log…I have a separate macro for saving images from logging into the website to keep things easy to edit.

Since your response, I made some changes to where my macro now functions as intended.

(I realized unique values were not necessary since the csv has no column headers, so I rewrite the same value with each new image and save to the csv)

I am still interested in how to store those values in the csv as an array instead of in separate columns

{
“Name”: “Image Extract-1”,
“CreationDate”: “2020-3-26”,
“Commands”: [
{
“Command”: “storeText”,
“Target”: “css=td.d77m39 > span”,
“Value”: “mls_number”
},
{
“Command”: “echo”,
“Target”: “The MLS number is {mls_number}", "Value": "blue" }, { "Command": "store", "Target": "{mls_number}”,
“Value”: “!csvLine”
},
{
“Command”: “verifyElementPresent”,
“Target”: “xpath=//*[@id=“m_DisplayCore_dpy1”]/div[2]/font[3]”,
“Value”: “”
},
{
“Command”: “gotoIf_v2”,
“Target”: “{!statusOK} == false", "Value": "no_images" }, { "Command": "echo", "Target": "Property Images Exist", "Value": "green" }, { "Command": "click", "Target": "xpath=//*[@id=\"m_DisplayCore_dpy1\"]/div[2]/font[3]", "Value": "" }, { "Command": "selectWindow", "Target": "tab=1", "Value": "" }, { "Command": "clickAndWait", "Target": "xpath=//*[@id=\"m_trGallery\"]/td/table/tbody/tr[1]/td[1]/a/img", "Value": "" }, { "Command": "storeText", "Target": "xpath=//*[@id=\"m_trPaging\"]/td/table/tbody/tr/td[2]/b[2]", "Value": "imgcount" }, { "Command": "echo", "Target": "Photo gallery contains {imgcount} photos”,
“Value”: “blue”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number ({imgcount}) - 1;", "Value": "last_image_saved" }, { "Command": "while_v2", "Target": "{last_image_saved} != {imgcount}", "Value": "" }, { "Command": "storeText", "Target": "xpath=//*[@id=\"m_trPaging\"]/td/table/tbody/tr/td[2]/b[1]/span", "Value": "current_img" }, { "Command": "storeAttribute", "Target": "xpath=//*[@id=\"m_trGallery\"]/td/div[1]/a/img@src", "Value": "image_src" }, { "Command": "storeText", "Target": "id=PopupCaption", "Value": "caption_{current_img}”
},
{
“Command”: “executeScript_Sandbox”,
“Target”: “return Number ({current_img});", "Value": "last_image_saved" }, { "Command": "store", "Target": "{image_src}”,
“Value”: “!csvLine”
},
{
“Command”: “echo”,
“Target”: “Image source {last_image_saved} of {imgcount} saved”,
“Value”: “green”
},
{
“Command”: “echo”,
“Target”: “Image {last_image_saved} source is {image_src}”,
“Value”: “green”
},
{
“Command”: “click”,
“Target”: “linkText=Next”,
“Value”: “”
},
{
“Command”: “endWhile”,
“Target”: “”,
“Value”: “”
},
{
“Command”: “csvSave”,
“Target”: “listing_export”,
“Value”: “”
},
{
“Command”: “echo”,
“Target”: “CSV saved”,
“Value”: “blue”
},
{
“Command”: “localStorageExport”,
“Target”: “listing_export.csv”,
“Value”: “”
},
{
“Command”: “echo”,
“Target”: “CSV downloaded”,
“Value”: “blue”
},
{
“Command”: “label”,
“Target”: “no_images”,
“Value”: “”
}
]
}

[status]

Playing macro Image Extract-1

[info]

Executing:  | storeText | css=td.d77m39 > span | mls_number | 

[info]

Executing:  | echo | The MLS number is ${mls_number} | blue | 

[echo]

The MLS number is PABU489780

[info]

Executing:  | store | ${mls_number} | !csvLine | 

[info]

Executing:  | verifyElementPresent | xpath=//*[@id="m_DisplayCore_dpy1"]/div[2]/font[3] |  | 

[info]

Executing:  | gotoIf_v2 | ${!statusOK} == false | no_images | 

[info]

Executing:  | echo | Property Images Exist | green | 

[echo]

Property Images Exist

[info]

Executing:  | click | xpath=//*[@id="m_DisplayCore_dpy1"]/div[2]/font[3] |  | 

[info]

Executing:  | selectWindow | tab=1 |  | 

[info]

Executing:  | clickAndWait | xpath=//*[@id="m_trGallery"]/td/table/tbody/tr[1]/td[1]/a/img |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[2] | imgcount | 

[info]

Executing:  | echo | Photo gallery contains ${imgcount} photos | blue | 

[echo]

Photo gallery contains 10 photos

[info]

Executing:  | executeScript_Sandbox | return Number (${imgcount}) - 1; | last_image_saved | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 1 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 1 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=0&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 2 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 2 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=1&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 3 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 3 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=2&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 4 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 4 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=3&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 5 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 5 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=4&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 6 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 6 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=5&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 7 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 7 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=6&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 8 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 8 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=7&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 9 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 9 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=8&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | storeText | xpath=//*[@id="m_trPaging"]/td/table/tbody/tr/td[2]/b[1]/span | current_img | 

[info]

Executing:  | storeAttribute | xpath=//*[@id="m_trGallery"]/td/div[1]/a/img@src | image_src | 

[info]

Executing:  | storeText | id=PopupCaption | caption_${current_img} | 

[info]

Executing:  | executeScript_Sandbox | return Number (${current_img}); | last_image_saved | 

[info]

Executing:  | store | ${image_src} | !csvLine | 

[info]

Executing:  | echo | Image source ${last_image_saved} of ${imgcount} saved | green | 

[echo]

Image source 10 of 10 saved

[info]

Executing:  | echo | Image ${last_image_saved} source is ${image_src} | green | 

[echo]

Image 10 source is https://matrixmedia.brightmls.com/mediaserver/GetMedia.ashx?Key=940833930&TableID=9&Type=1&Number=9&Size=4&exk=2a870d502121ecb4686a57fb3eacf52a

[info]

Executing:  | click | linkText=Next |  | 

[info]

Executing:  | endWhile |  |  | 

[info]

Executing:  | while_v2 | ${last_image_saved}  != ${imgcount} |  | 

[info]

Executing:  | csvSave | listing_export |  | 

[info]

Executing:  | echo | CSV saved | blue | 

[echo]

CSV saved

[info]

Executing:  | localStorageExport | listing_export.csv |  | 

[info]

Executing:  | echo | CSV downloaded | blue | 

[echo]

CSV downloaded

[info]

Executing:  | label | no_images |  | 

[info]

Macro completed (Runtime 44.88s)

Hi in my opinion this macro code is complex and hard to understand is easy to give error complex code.

I suggest to create a simply macro image grabber with few line of codes have few chances to give error.

I already have created grabber and I prefer few line of cose to prevent stuck and error of ui vision.

Create a simple grab images and save in csv require few line of codes, other command can confuse the macro code and create error.

From sometimes i create micro macro code (few lines) and i run more micro macro via test suite.

Micro macro are simple to edit, fast and rarely give errors and bug.

When a micro macro have an error i can read log and know the reason to generate the error.