Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can someone help with using CSV files and Arrays?
#1
Hello,
I'm new to scripting and I'm hoping that someone here has done this before. I would appreciate the help and it would save me a LOT of time going in circles and ending up with a mess.

I'm trying to creating a macro to open a web page that has text boxes on it and fill the multiple boxes out using information from a CSV file. It's for a company I'm working for. They want to create a bunch of accounts on a web site and would like to do it quickly with a CSV file from HR with all the employees information in it. I know there will be some sort of capchia but I can manually put that in each time. It's better than typing All of the info each time.

Anyone got time to help me get started?

Thanks for any help!
#2
example
Macro fill web form from CSV
Code:
Copy      Help
;create CSV string for testing
str csv=
;A1, B1, C1
;A2, B2, C2
;A3, B3, C3

;load the CSV into a variable
ICsv x._create
x.FromString(csv) ;;replace to FromFile("c:\...\your CSV file.csv")

;open the web page
run "iexplore" "https://www.google.com/advanced_search"
mes- "please wait until Internet Explorer opens Google advanced search page. This macro uses it as an example of a web form with multiple edit boxes" "" "OCi"

;get IE window handle
int w=wait(3 WV win("" "IEFrame"))

;repeat for each row in CSV
int i n=x.RowCount
for i 0 n
,;find first edit box in web page
,Htm e=htm("INPUT" "as_q" "" w "0" 0 0x221 3) ;;to create this code, use dialog 'Find HTML element'
,;set its text from CSV first column
,e.SetText(x.Cell(i 0))
,;do the same with other edit boxes and CSV columns
,e=htm("INPUT" "as_epq" "" w "0" 1 0x221 3)
,e.SetText(x.Cell(i 1))
,e=htm("INPUT" "as_oq" "" w "0" 2 0x221 3)
,e.SetText(x.Cell(i 2))
,;find and click a Submit button
,e=htm("INPUT" "submit" "" w "0" 14 0x521 3)
,e.Click
,;now you can open another such form, and the macro will fill the edit boxes with next CSV row
,if(i<n-1) mes- "click OK when ready to repeat with next CSV row" "" "OCi"
,else mes "Done" "" "Oi"
,
#3
Thank you for the help! I think I'm getting it! I used to program VB a few years back but this is totally different of course.

Got a couple more questions if you don't mind.

When I set the str csv= value, what do you mean by ;A1,B1,C1 etc.... Do I have to set a variable for every cell in the cvs file? That will be a LOT. Each file is probably about 14 columns X 40 rows or more.

What could I use in the line below to be able to choose the csv file instead of hard coding it?
x.FromString(csv) ;;replace to FromFile("c:\...\your CSV file.csv")
#4
A1,A2 etc is an example CSV string, not variables. Remove that code, it is just for testing. To choose file, use function OpenSaveDialog.
#5
This little project has went great, thanks to your help. I really appreciate it. I've ran into one small problem, I hope. One of the fields on the form will not take the "SetText" function. It has an example in it, it's light grey in color, and when I set the text with the macro it stays light grey and doesn't turn into regular text as when it's typed. I cannot "paste" a value into this field either. Is there a way around it without typing it in each time?
I've tried to "SetFocus" before putting using the "SetText" function and it didn't work. I even went to the previous field and after filling it out sent a keyboard "Tab" to that field and it wouldn't take it. Seem to be field that they didn't want a macro or paste command to fill it out but I really need to put that value in from the csv file.

Thanks!
#6
This little project has went great, thanks to your help. I really appreciate it. I've ran into one small problem, I hope. One of the fields on the form will not take the "SetText" function. It has an example in it, it's light grey in color, and when I set the text with the macro it stays light grey and doesn't turn into regular text as when it's typed. I cannot "paste" a value into this field either. Is there a way around it without typing it in each time?
I've tried to "SetFocus" before putting using the "SetText" function and it didn't work. I even went to the previous field and after filling it out sent a keyboard "Tab" to that field and it wouldn't take it. Seem to be field that they didn't want a macro or paste command to fill it out but I really need to put that value in from the csv file.

Thanks!
#7
Try:
e.Mouse(1)
_s=x.Cell(i 2)
key (_s)
#8
The e.Mouse(1) didn't do it but e.Click with the rest of the code did!

Thank you!

Now, you don't know how to read a CAPTCHA do you? :-)
#9
don't know
#10
Gintaras - A Sincere THANK YOU! I appreciate the help. You save me so much time.
#11
re:captcha

Depends on how hard the captchas are. There are various services (pay as you go) and software (pay once) that you can use. You'd have to write a function to identify, capture, and send the captcha to the captcha solving service.


Forum Jump:


Users browsing this thread: 6 Guest(s)