How to Upload image with variable ID?

Support for iMacros. The iMacros software is the unique solution for automating every activity inside a web browser, for data extraction and web testing.
Forum rules
iMacros EOL - Attention!

The renewal maintenance has officially ended for Progress iMacros effective November 20, 2023 and all versions of iMacros are now considered EOL (End-of-Life). The iMacros products will no longer be supported by Progress (aside from customer license issues), and these forums will also no longer be moderated from the Progress side.

Thank you again for your business and support.

Sincerely,
The Progress Team

Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the search box (at the top of each forum page) to see if a similar problem or question has already been addressed.
3. Try searching the iMacros Wiki - it contains the complete iMacros reference as well as plenty of samples and tutorials.
4. We can respond much faster to your posts if you include the following information: CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST
Post Reply
rawpanda
Posts: 2
Joined: Thu Jan 13, 2022 10:42 pm

How to Upload image with variable ID?

Post by rawpanda » Fri Jan 14, 2022 12:15 am

Hi guys,
I was trying to upload images to a website by using .csv file but failed, every times I go to uploading page, it will be a new ID like this:
Image

And this is the macro when i recorded:

Code: Select all

TAG POS=1 TYPE=DIV ATTR=CLASS:"m-uploader__dropzone-icon icon tp-file-single"
TAG POS=1 TYPE=INPUT:FILE ATTR=NAME:file CONTENT="C:\\fakepath\\WEDDING 40 1.png"
' there isn't anything like: ATTR=ID:*
I tried to edit the macro:

Code: Select all

VERSION BUILD=2021
TAB T=1
TAB CLOSEALLOTHERS
SET !PLAYBACKDELAY 0.2
SET !DATASOURCE Teepublic.csv
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=https://www.teepublic.com/
TAG POS=2 TYPE=A ATTR=HREF:https://www.teepublic.com/design/quick_create
TAG POS=1 TYPE=DIV ATTR=CLASS:"m-uploader__dropzone-icon icon tp-file-single"
TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT={{!COL1}}
But it still failed, imacros didn't upload the file to the website.

I'm using imacros 2021 app version, Window 10 Home Edition.

Please help to fix this.
Thank you very much in advance!
chivracq
Posts: 10301
Joined: Sat Apr 13, 2013 1:07 pm
Location: Amsterdam (NL)

Re: How to Upload image with variable ID?

Post by chivracq » Fri Jan 14, 2022 4:17 am

rawpanda wrote:
Fri Jan 14, 2022 12:15 am
Hi guys,
I was trying to upload images to a website by using .csv file but failed, every times I go to uploading page, it will be a new ID like this:
Image

And this is the macro when i recorded:

Code: Select all

TAG POS=1 TYPE=DIV ATTR=CLASS:"m-uploader__dropzone-icon icon tp-file-single"
TAG POS=1 TYPE=INPUT:FILE ATTR=NAME:file CONTENT="C:\\fakepath\\WEDDING 40 1.png"
' there isn't anything like: ATTR=ID:*
I tried to edit the macro:

Code: Select all

VERSION BUILD=2021
TAB T=1
TAB CLOSEALLOTHERS
SET !PLAYBACKDELAY 0.2
SET !DATASOURCE Teepublic.csv
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=https://www.teepublic.com/
TAG POS=2 TYPE=A ATTR=HREF:https://www.teepublic.com/design/quick_create
TAG POS=1 TYPE=DIV ATTR=CLASS:"m-uploader__dropzone-icon icon tp-file-single"
TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT={{!COL1}}
But it still failed, imacros didn't upload the file to the website.

I'm using

Code: Select all

imacros 2021 app version, Window 10 Home Edition.
Please help to fix this.
Thank you very much in advance!

I don't understand what you mean exactly by "ID"...? :?
=> Is it the "40 1" Part in the Filename...?

The only "ID" I see in your Script is the 'ID' for the 'FORM' Param in:

Code: Select all

TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT={{!COL1}}
The 'FORM' Param can usually be omitted, unless there are several Forms on the Page, and it was not even present in the mini-Script you said had been recorded by iMacros:

Code: Select all

TAG POS=1 TYPE=INPUT:FILE ATTR=NAME:file CONTENT="C:\\fakepath\\WEDDING 40 1.png"
"But it still failed, imacros didn't upload the file to the website.":
=> Do you still get the Upload Popup or not...?
If = Yes, you included the whole Path (+ Filename) in your '.csv' DataSource, => did you make sure to double the Backslashes everywhere in the Paths like visible in the mini recorded Script, as you are using Double Quotes for the 'CONTENT' Param as your Path probably contains Spaces, and the Filename does anyway...?
... But hum..., no, wait...!, this is not correct, I think..., => as because you are using the '!COL1' Var, iMacros should be able to handle Spaces by itself, and can even accept (Single) Backslashes + Double Backsalshes + even Single and Double Forward Slashes, even on Windows...
The "thing" is, even if you've specified your Path + Filename as "C:\\fakepath\\WEDDING 40 1.png" (with the Double Quotes) in your '.csv', those Double Quotes will be ignored when running the Script..., => safer might be to replace all Spaces with "<SP>" (without Quotes), or maybe you can try:

Code: Select all

TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT="{{!COL1}}"
=> With Double Quotes surrounding the '!COL1' Var...
I'm not sure, I would need to test... :oops:
... And even "safer" is to try to avoid all Spaces in Paths and Filenames, ah-ah...! :P

And if all Files/Images are located in the same Folder, it might be "easier" to only specify the Filename in your '.csv' and to hard-code the Path to that Folder, ... or to use a Var... :idea:

>>>

If you don't come out by yourself, I could have a Look at the Site, if you can share some Test Account... :idea:
Or if you don't want to share some Login & Password "publicly", you can also "fake-report" my Post, then only myself (Mod on the Forum) and the Forum Admin (= @TechSup) will be able to see your Msg/Report...
- (F)CI(M) = (Full) Config Info (Missing): iMacros + Browser + OS (+ all 3 Versions + 'Free'/'PE'/'Trial').
- FCI not mentioned: I don't even read the Qt...! (or only to catch Spam!)
- Script & URL help a lot for more "educated" Help...
rawpanda
Posts: 2
Joined: Thu Jan 13, 2022 10:42 pm

Re: How to Upload image with variable ID?

Post by rawpanda » Fri Jan 14, 2022 7:15 am

Hi chivracq,
Thank you for your help,
chivracq wrote:
Fri Jan 14, 2022 4:17 am
I don't understand what you mean exactly by "ID"...? :?
=> Is it the "40 1" Part in the Filename...?
The only "ID" I see in your Script is the 'ID' for the 'FORM' Param in:

Code: Select all

TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT={{!COL1}}
==> I tried to attach an image with source code of the uploading page (with variable ID) in my post but it isn't showed up correctly.
The image link: https://ibb.co/mCN15T7
chivracq wrote:
Fri Jan 14, 2022 4:17 am
"But it still failed, imacros didn't upload the file to the website.":
=> Do you still get the Upload Popup or not...?
If = Yes, you included the whole Path (+ Filename) in your '.csv' DataSource, => did you make sure to double the Backslashes everywhere in the Paths like visible in the mini recorded Script, as you are using Double Quotes for the 'CONTENT' Param as your Path probably contains Spaces, and the Filename does anyway...?
... But hum..., no, wait...!, this is not correct, I think..., => as because you are using the '!COL1' Var, iMacros should be able to handle Spaces by itself, and can even accept (Single) Backslashes + Double Backsalshes + even Single and Double Forward Slashes, even on Windows...
==> I don't think there is any problem with the 'Space' in the Path to .PNG file - because I tried the same .csv file on another site and it worked perfectly.
chivracq wrote:
Fri Jan 14, 2022 4:17 am

Code: Select all

TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT="{{!COL1}}"
=> With Double Quotes surrounding the '!COL1' Var...
==> I tested the macro with double quotes surrounding the '!COL1' Var and it has the same result as without double quotes.

During my tests, I found out that after running my old script, if I click the Uploading box MANUALLY, the page will load the image file without me re-choosing the path, so I changed the scripts and it worked:

Code: Select all

VERSION BUILD=2021
TAB T=1
TAB CLOSEALLOTHERS
SET !PLAYBACKDELAY 0.2
SET !DATASOURCE Teepublic.csv
SET !LOOP 2
SET !DATASOURCE_LINE {{!LOOP}}
URL GOTO=https://www.teepublic.com/
TAG POS=2 TYPE=A ATTR=HREF:https://www.teepublic.com/design/quick_create
TAG POS=1 TYPE=DIV ATTR=CLASS:"m-uploader__dropzone-icon icon tp-file-single"
TAG POS=1 TYPE=INPUT:FILE FORM=ID:edit_design_* ATTR=NAME:file CONTENT={{!COL1}}
TAG POS=1 TYPE=DIV ATTR=CLASS:"m-uploader__dropzone-icon icon tp-file-single"
' I added that last line and it worked :D
Anyway, thank you so much for the help.
Have a very nice day!
Post Reply