Electron microscopy
 
Upload Files to Webpages
- Integrated Circuits -
- An Online Book -
Integrated Circuits                                                                                   http://www.globalsino.com/ICs/        


Chapter/Index: Introduction | A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | S | T | U | V | W | X | Y | Z | Appendix

=================================================================================

The problem with file upload is, once the upload button is clicked, then the select file dialog box which opens up is a owned by the OS, not the browser, so Selenium cannot control it anymore, one need to find other way around it. It can be done to bypass the “select file” dialog box completely, passing the file-path to the webpage without ever opening it. Something needs to know before a script is generated for file uploading:
        i) if the webpage is handling a file-upload, it must be having an input tag with type=file in it.
        ii) Check if Selenium can access this input tag or not.
        iii) Use different "find_element_by_*" on indexF. But this method doesn’t always work. Errors usually happens when the webpage handles file upload through some JavaScript sorcery, instead of going the normal way. In that case, the input element of input needs to be modified in order to make it accessible to Selenium with JavaScript snippet (the second line below), followed by the normal "input" command:
           fileinput = driver.find_element_by_css_selector('input.dz-hidden-input')
           driver.execute_script('arguments[0].style = ""; arguments[0].style.display = "block"; arguments[0].style.visibility = "visible";', fileinput)
        iv) If there is no "input type" element (e.g. that is shown below -- this case is normally used to prevent users from submitting a form by hitting Enter), a solution is to ask your frontend website developer to change the button for file upload.
          Upload Files to Webpages

============================================

Refer to Selenium.

============================================

Upload files by using Selenium ("input"does not have "id", then use "XPATH" to upload a file):    
          Upload Files to Webpages
Go to the inspect, and then right click to "Copy XPath":          
          Upload Files to Webpages
          Upload Files to Webpages

The obtained XPath is "//*[@id="resumable-browse"]/input", then paste it into the code: Code:
          Upload Files to Webpages
============================================

Upload files by using Selenium (always use "input" for "send_key"):         
         i) Go to the website.
         ii) Right click "Upload File"
          Upload Files to Webpages
          This case is more complicated: need to scroll down and trace the code (see image and the obtained "layers" below), and then find "input ..." and "type = "file" " there is the most important thing, where the location the file will be sent.
         Upload Files to Webpages
          The "layers" give:
             "//div[@id='uploader_buttons']/div/input"
          And, the submission will be the same if there is one.
          Upload Files to Webpages
Code:
          Upload Files to Webpages
Output:         
          Upload Files to Webpages
          Upload Files to Webpages
          Upload Files to Webpages

============================================

Upload files by using Selenium (always use "input" for "send_key"):    
          Upload Files to Webpages
Code:
          Upload Files to Webpages

============================================

Upload files with full XPATH when there are "multiple id":    
         Upload Files to Webpages
         Upload Files to Webpages
         Upload Files to Webpages
         Upload Files to Webpages
Then, the full XPATH is obtained: /html/body/form/div[3]/div[1]/section[2]/div/div[2]/div[2]/div[4]/div/label[1]/input.    
Code
:
          Upload Files to Webpages
Output:         
          Upload Files to Webpages
         
         
         
         
         
         
         
         
         
         
         

 

 

 

 

 

 

 

 

 

 

=================================================================================