Advertisement
Guest User

automate file upload

a guest
Mar 15th, 2020
677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. https://www.youtube.com/watch?v=7a8IofqBNo4&t=1s
  2.  
  3. Hi Ashu. great code! Thanks for sharing.
  4. I have successfully applied your selenium method for the data entry part, but now I can't upload 2 files on two separate uploading prompt buttons on the same page, because the script of this tutorial is for IE.
  5.  
  6.  
  7. Does it work with your selenium method?
  8. Is it possible to upload from paths as input in excel cells—not hard-coded/strings files paths?
  9. I mean if I prepare a list of files paths from the same folder and input them into excel cells and then take the values of the excel cells from the cells references as per your example?
  10.  
  11. For example:
  12. I manually paste the 1st file path into cell A2, Sheet "Data", same Workbook as the VBA Code, the path of 2nd file into A3:
  13. A2 cell (string) value = C:\Users\XXX\Pictures\text1.txt
  14. A3 cell (string) value = C:\Users\XXX\Pictures\text2.txt
  15.  
  16.  
  17. Can I make something like:
  18.  
  19.  
  20. Sub uploadFiles()
  21.  
  22. Dim robot As New ChromeDriver, Keys As New Keys
  23.  
  24.  
  25. 'OPEN the webpage: https://www.automationandagile.com/p/sample-form.html
  26. robot.Get "https://www.automationandagile.com/p/sample-form.html"
  27.  
  28.  
  29. 'WAIT 3 seconds for the webpage to load and then execute the following code
  30. robot.Wait 3000
  31.  
  32.  
  33. 'CLICK the webpage's 1st upload prompt button
  34. robot.FindElementByXPath("//*[@id='WEBUPLOADBUTTON1']").Click
  35.  
  36.  
  37.  
  38. 'the path of the VBS file on my C Drive AS constant/hard-coded "Variable" string
  39. strFile = "C:\Excel_Automation\Files\FileUpload.vbs"
  40.  
  41.  
  42. 'the path of the 1st file (text1.txt) on my C Drive to be uploaded, but as input into cell A2 of the current excel workbook, of Sheet named "Data" AS dynamic/variable excel cell reference
  43. strUploadFile1 = (ThisWorkbook.Sheets("Data").Range("A2").Value)
  44.  
  45.  
  46. 'syntax of the VBS uploading method (Shell "_exescript_" & VBS FIle Path & " space_" & _Uploadfile )
  47. Shell "wscript.exe " & strFile & " " & strUploadFile
  48. 1
  49.  
  50.  
  51.  
  52.  
  53. 'CLICK the webpage's 2nd upload prompt button
  54. robot.FindElementByXPath("//*[@id='WEBUPLOADBUTTON2']").Click
  55.  
  56. 'the path of the 2nd file (text2.txt) on my C Drive to be uploaded, but as input into cell A3 of the current excel workbook, of Sheet named "Data" AS dynamic/variable excel cell reference
  57. strUploadFile2 = (ThisWorkbook.Sheets("Data").Range("A3").Value)
  58.  
  59.  
  60. 'syntax of the VBS uploading method (Shell "_exescript_" & VBS FIle Path & " space_" & _Uploadfile )
  61. Shell "wscript.exe " & strFile & " " & strUploadFile
  62. 2
  63.  
  64.  
  65. End Sub
  66.  
  67.  
  68. Would it work like this? Anything missing? Do you see a better way to do it?
  69. Would you please make a video to upload 2 files with selenium on Chrome Browser?
  70. Thanks for your help.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement