virtualfred Posted August 11, 2007 Share Posted August 11, 2007 Hi Am am having trouble with filling a multipart form. You need to browse for a file to upload but i would like to pull the file path from a text file but i am having trouble sending the info with send. Here's the code i have got but im not sure how to pull the info into the send. $csvfile = FileReadLine($url2) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") _IEFormElementSetValue ($oInputFile,$csvfile) ; Assign input focus to the field and then send the text string _IEAction($oInputFile, "focus") Send (_IEFormElementSetValue ($oInputFile,$csvfile) Thanks for your time. Link to comment Share on other sites More sharing options...
Gif Posted August 11, 2007 Share Posted August 11, 2007 please tell us the site, anyway this is for the INPUT=FILE:$ispe = FileOpen($url2, 0) $csvfile = FileReadLine($ispe) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") _IEAction($oInputFile, "focus") ControlSend(TITLE OF THE WINDOW HERE, '', 'Internet Explorer_Server1', $cvsfile) FileClose($ispe) Exit Link to comment Share on other sites More sharing options...
virtualfred Posted August 12, 2007 Author Share Posted August 12, 2007 Hi Thanks for your help so far but i just cant get this to work, what should i be putting in the control send line where it says TITLE OF THE WINDOW HERE i have tried just about every thing but no luck. Thanks $ispe = FileOpen($url2, 0) $csvfile = FileReadLine($ispe) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") _IEAction($oInputFile, "focus") ControlSend(TITLE OF THE WINDOW HERE, '', 'Internet Explorer_Server1', $cvsfile) FileClose($ispe) Exit Link to comment Share on other sites More sharing options...
ResNullius Posted August 12, 2007 Share Posted August 12, 2007 Hi Thanks for your help so far but i just cant get this to work, what should i be putting in the control send line where it says TITLE OF THE WINDOW HERE i have tried just about every thing but no luck. ThanksYou don't need any Send() or ControlSend(). The code from your first post should work for setting the text, provided - you have created a valid IE object using _IECreate() or you've attached to an existing instance with _IEAttach() you have your form/element names correct your variable $csvfile actually contains something...Then you just need to add an IEFormSubmit() $csvfile = FileReadLine($url2) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") _IEFormElementSetValue ($oInputFile,$csvfile) IEFormSubmit($oForm) Perhaps you can post more of your code, and as Gif said, tell us the website this is for. Link to comment Share on other sites More sharing options...
virtualfred Posted August 12, 2007 Author Share Posted August 12, 2007 Hi the site is password protected and i dont want to post the details on here. I have tried the code you gave me but no info is pulled from the csvfile and the form is left blank. Here is the form i want to send to. CODE<h5>Keyword CSV File</h5> <form action="Keywords.php" method="post" name="upload_csv" id="upload_csv" enctype="multipart/form-data" class="awesome"> <input name="step" type="hidden" value="3" /> <input name="input_method" type="hidden" value="csv" /> <h6>Upload Keyword CSV File</h6> <p>Click the 'Browse' button to locate the csv file containing the keywords and optional redirect urls on your computer.</p> <label for="csv_file">Keyword CSV File</label> <input name="csv_file" id="csv_file" type="file" size="35" /><br /> <p class="desc">The file uploaded MUST be a .csv file.</p> <label for="sep_by">Fields are separated by</label> <select id="sep_by" name="sep_by"> <option value=",">Comma ( , )</option> <option value=";">Semi-Colon ( ; )</option> </select><br /> Here is the rest of my code. (probable not the best looking but this is my first try with autoit) All the rest of the fields are filled ok and i can fill the first part if i just send some text i just cant pull the info from the csvfile. CODEOpt("SendKeyDelay", 1) Opt("wintitlematchmode",2) $site = InputBox("domain number", "number of domains?", "", "") $redirect = FileOpen("colon.txt", 0) $url = FileOpen("domain.txt", 0) $url2 = FileOpen("csvdomain.txt", 0) $url4 = FileOpen("login.txt", 0) HotKeySet("{ESC}", "exitFunc" ) Func exitFunc () Exit EndFunc $begin = TimerInit() ;open ie to login to ssec app.. $login = FileReadLine($url4,2) $pass = FileReadLine($url4,3) $appurl = FileReadLine($url4,1) #include <IE.au3> $oIE = _IECreate ($appurl) WinSetState("Internet Explorer","",@SW_MAXIMIZE) Sleep(200) $oForm = _IEFormGetCollection ($oIE, 0) $oQuery = _IEFormElementGetCollection ($oForm, 0) $oQuery2 = _IEFormElementGetCollection ($oForm, 1) _IEFormElementSetValue ($oQuery,$login) _IEFormElementSetValue ($oQuery2, $pass) $oSubmit = _IEFormElementGetCollection ($oForm,2) _IEAction ($oSubmit, "click") _IELoadWait($oIE) For $X = 1 TO $site Step 1 $csv = FileReadLine($url) $comma = FileReadLine($redirect) $password = FileReadLine($url2) $csvfile = FileReadLine($url2) $num=Random(1,99999,1) $whm = stringleft ($csv,2) $whmaccount=$WHM & $NUM _IELinkClickByText($oIE,"Manage keywords") $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") _IELoadWait($oIE) $csvfile = FileReadLine($url2) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") _IEFormElementSetValue ($oInputFile,$csvfile) ; fill form for domain insertion $o_form = _IEFormGetObjByName ($oIE, "upload_csv") $o_input = _IEFormElementGetObjByName ($o_form, "step") $o_input1 = _IEFormElementGetObjByName ($o_form, "input_method") $o_login = _IEFormElementGetObjByName ($o_form, "csv_file") $o_password = _IEFormElementGetObjByName ($o_form, "sep_by") $o_domain = _IEFormElementGetObjByName ($o_form, "domain_id") $o_signin = _IEFormElementGetObjByName ($o_form, "upload_csv") ; Set field values and submit the form _IEFormElementSetValue ($o_input, $csv) _IEFormElementSetValue ($o_login, $csv) _IEFormElementSetValue ($o_password, $comma) _IEFormElementSetValue ($o_domain, $password) _IELoadWait($oIE) $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") _IELoadWaitTimeout(180000) _IELoadWait($oIE) Sleep(500) next $end = TimerDiff($begin) $endtime1 = $end / 1000 $endtime15 = $endtime1 / 60 $endtime2 = Int($endtime15) MsgBox(4096,"Finished!", $site & " " & $endtime2 & " minutes! " ) Link to comment Share on other sites More sharing options...
virtualfred Posted August 12, 2007 Author Share Posted August 12, 2007 Cleaned the code up a bit now and tried every way i can find to send the info but still no luck. I can send some text to the part of the form thats giving me trouble but nothing from a file. CODEOpt("SendKeyDelay", 1) Opt("wintitlematchmode",2) $site = InputBox("domain number", "number of domains?", "", "") $comma = FileOpen("comma.txt", 0) $csv = FileOpen("csv.txt", 0) $domainid = FileOpen("domainid.txt", 0) $url4 = FileOpen("login.txt", 0) $csvfile = FileOpen("csvfile.txt", 0) $inputmethod = FileOpen("inputmethod.txt", 0) HotKeySet("{ESC}", "exitFunc" ) Func exitFunc () Exit EndFunc $begin = TimerInit() $login = FileReadLine($url4,2) $pass = FileReadLine($url4,3) $appurl = FileReadLine($url4,1) #include <IE.au3> $oIE = _IECreate ($appurl) WinSetState("Internet Explorer","",@SW_MAXIMIZE) Sleep(200) $oForm = _IEFormGetCollection ($oIE, 0) $oQuery = _IEFormElementGetCollection ($oForm, 0) $oQuery2 = _IEFormElementGetCollection ($oForm, 1) _IEFormElementSetValue ($oQuery,$login) _IEFormElementSetValue ($oQuery2, $pass) $oSubmit = _IEFormElementGetCollection ($oForm,2) _IEAction ($oSubmit, "click") _IELoadWait($oIE) For $X = 1 TO $site Step 1 $csv = FileReadLine($csv) $inputmethod = FileReadLine($inputmethod) $csvfile = FileReadLine($csvfile) $comma = FileReadLine($comma) $domainid = FileReadLine($domainid) $num=Random(1,99999,1) $whm = stringleft ($csv,2) $whmaccount=$WHM & $NUM _IELinkClickByText($oIE,"Manage keywords") $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") _IELoadWait($oIE) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") ; Assign input focus to the field and then send the text string _IEAction($oInputFile, "focus") $hIE = _IEPropertyGet($oIE, "hwnd") ControlSend($hIE, "", "Internet Explorer_Server1", $oInputFile,$csvfile) _IELoadWait($oIE) ; fill form for domain insertion $o_form = _IEFormGetObjByName ($oIE, "upload_csv") $o_csv = _IEFormElementGetObjByName ($o_form, "step") $o_inputmethod = _IEFormElementGetObjByName ($o_form, "input_method") $o_comma = _IEFormElementGetObjByName ($o_form, "sep_by") $o_domainid = _IEFormElementGetObjByName ($o_form, "domain_id") ; Set field values and submit the form _IEFormElementSetValue ($o_csv, $csv) _IEFormElementSetValue ($o_inputmethod, $inputmethod) _IEFormElementSetValue ($o_comma, $comma) _IEFormElementSetValue ($o_domainid, $domainid) _IELoadWait($oIE) $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") _IELoadWaitTimeout(180000) _IELoadWait($oIE) Sleep(500) next $end = TimerDiff($begin) $endtime1 = $end / 1000 $endtime15 = $endtime1 / 60 $endtime2 = Int($endtime15) MsgBox(4096,"Finished!", $site & " " & $endtime2 & " minutes" ) Link to comment Share on other sites More sharing options...
ResNullius Posted August 13, 2007 Share Posted August 13, 2007 Cleaned the code up a bit now and tried every way i can find to send the info but still no luck. I can send some text to the part of the form thats giving me trouble but nothing from a file. So, the problem must be in getting the info from your files. Have you tried message boxes to test the variables after reading the files? For $X = 1 TO $site Step 1 $csv = FileReadLine($csv) MsgBox(4096,"CSV","CSV = " & $CSV) $inputmethod = FileReadLine($inputmethod) MsgBox(4096,"INPUTMETHOD","INPUTMETHOD = " & $inputmethod) $csvfile = FileReadLine($csvfile) MsgBox(4096,"CSVFILE","CSVFILE = " & $csvfile) $comma = FileReadLine($comma) MsgBox(4096,"COMMA","COMMA = " & $COMMA) $domainid = FileReadLine($domainid) MsgBox(4096,"DOMAINID","DOMAINID = " & $domainid) $num=Random(1,99999,1) MsgBox(4096,"NUM","NUM = " & $num) $whm = stringleft ($csv,2) MsgBox(4096,"WHM","WHM = " & $whm) $whmaccount=$WHM & $NUM Also, I think you'll run into problems with your for loop because you have file handles you've opened, like in $csv = FileOpen("csv.txt", 0) and then you go and reuse the variable for the actual contents you're trying to read: $csv = FileReadLine($csv). I'm sure this guarantees that the handle now no longer points to the file so there's no way you can read from it on the next step through the loop. And finally, can you post a mockup sample of the various files your reading from? Link to comment Share on other sites More sharing options...
virtualfred Posted August 13, 2007 Author Share Posted August 13, 2007 Everything works now apart from filling csv_file i have tried every way i can find but no luck. It will fill it if i just use text but when i try to pull it from the txt file theres no text. I tried your bit of code and it is pulling the info in that ok, and idea what it could be. Thanks CODEOpt("SendKeyDelay", 1) Opt("wintitlematchmode",2) $site = InputBox("domain number", "number of domains?", "", "") $domainidfile = FileOpen("filedomainid.txt",0) $url4 = FileOpen("filelogin.txt",0) $csvfilefile = FileOpen("filecsvfile.txt",0) HotKeySet("{ESC}", "exitFunc" ) Func exitFunc () Exit EndFunc $begin = TimerInit() ;open ie to login to app.. $login = FileReadLine($url4,2) $pass = FileReadLine($url4,3) $appurl = FileReadLine($url4,1) #include <IE.au3> $oIE = _IECreate ($appurl) WinSetState("Internet Explorer","",@SW_MAXIMIZE) Sleep(200) $oForm = _IEFormGetCollection ($oIE, 0) $oQuery = _IEFormElementGetCollection ($oForm, 0) $oQuery2 = _IEFormElementGetCollection ($oForm, 1) _IEFormElementSetValue ($oQuery,$login) _IEFormElementSetValue ($oQuery2, $pass) $oSubmit = _IEFormElementGetCollection ($oForm,2) _IEAction ($oSubmit, "click") _IELoadWait($oIE) _IELinkClickByText($oIE,"Manage keywords") $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") For $X = 1 TO $site Step 1 _IELinkClickByText($oIE,"Manage keywords") $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") _IELoadWait($oIE) ; fill form for domain insertion $commafile = FileOpen("filecomma.txt", 0) $csvfile = FileOpen("filecsv.txt", 0) $inputmethodfile = FileOpen("fileinputmethod.txt", 0) $csv1 = FileReadLine($csvfile) $inputmethod1 = FileReadLine($inputmethodfile) $domainid1 = FileReadLine($domainidfile) $oForm = _IEFormGetObjByName($oIE, "upload_csv") $oInputFile = _IEFormElementGetObjByName($oForm, "csv_file") ; Assign input focus to the field and then send the text string _IEAction($oInputFile, "focus") $hIE = _IEPropertyGet($oIE, "hwnd") ControlSend($oIE, "", "Internet Explorer_Server1", $oInputFile, $csvfilefile) $o_form = _IEFormGetObjByName ($oIE, "upload_csv") $o_csv = _IEFormElementGetObjByName ($o_form, "step") $o_inputmethod = _IEFormElementGetObjByName ($o_form, "input_method") $o_domainid = _IEFormElementGetObjByName ($o_form, "domain_id") ; Set field values and submit the form _IEFormElementSetValue ($o_csv, $csv1) _IEFormElementSetValue ($o_inputmethod, $inputmethod1) _IEFormElementSetValue ($o_domainid, $domainid1) _IELoadWait($oIE) $oSubmit = _IEGetObjByName ($oIE, "submit") _IEAction ($oSubmit, "click") _IELoadWait($oIE) $csvfile = FileReadLine($csvfilefile) MsgBox(4096,"CSVFILE","CSVFILE = " & $csvfile) _IELoadWait($oIE) Sleep(500) next $end = TimerDiff($begin) $endtime1 = $end / 1000 $endtime15 = $endtime1 / 60 $endtime2 = Int($endtime15) MsgBox(4096,"Finished!", $site & " " & $endtime2 & " minutes" ) Link to comment Share on other sites More sharing options...
ResNullius Posted August 13, 2007 Share Posted August 13, 2007 And finally, can you post a mockup sample of the various files your reading from?? Link to comment Share on other sites More sharing options...
virtualfred Posted August 13, 2007 Author Share Posted August 13, 2007 The files are just text files with every new string on a new line like this. new string 1 new string 2 new string 3 new string 4 Thanks Link to comment Share on other sites More sharing options...
ResNullius Posted August 14, 2007 Share Posted August 14, 2007 Everything works now apart from filling csv_file i have tried every way i can find but no luck. It will fill it if i just use text but when i try to pull it from the txt file theres no text. I tried your bit of code and it is pulling the info in that ok, and idea what it could be. First, the following two lines don't make sense: $hIE = _IEPropertyGet($oIE, "hwnd") ControlSend($oIE, "", "Internet Explorer_Server1", $oInputFile, $csvfilefile)oÝ÷ Ù.ëmèZÙ^¶ax0whÂ)íçâ®ËewºÛazx§¶¬yÊ'vX§{*.v÷öÛ¬z+r¢ë¬zØ^Ó~¨ Jç-{-y§@ܨº»2Ö±~¢{k¢TجjYlr·°Èl¥u·ºÚ"µÍÛÛÛÙ[ ÌÍÚQK ][ÝÉ][ÝË ][ÝÒ[]^ÜÔÙI][ÝË ÌÍØÜÝ[Y[JoÝ÷ Ø Ý~)Ú²¢ë!¢é]mæëhv°k,"¶ax*'¶º%IéÝjÇb±Ë¬±ç^j¹bz¶§v;¬µÚ¢¹éÔµV¥¹æ®¶seôTf÷&ÔVÆVÖVçE6WEfÇVRb33c¶ôçWDfÆRÂb33c¶77c After that I'm lost, as you then go on to use SetValue statements but I can't really tell what you're trying to do. Perhaps you could give me an example of what the value of each of the elements should be before you submit the form... Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now