I present below two ways to upload a . The first uses Python Selenium in a special case (invisible input), the second handles a Windows Dialog Box.

Invisible input

If the input is hidden, make it visible. Here is an example (Python).
The input is hidden at the bottom of the page and looks like this:

<input type="file" multiple="multiple" class="dz-hidden-input" style="visibility: hidden; position: absolute; top: 0px; left: 0px; height: 0px; width: 0px;">

Now let’s see how to send the file (note the use of an absolute path):

file_input = driver.find_element_by_xpath("//input[@class = 'dz-hidden-input']")
# make the input visible:
driver.execute_script('arguments[0].style = ""; arguments[0].style.display = "block"; arguments[0].style.visibility = "visible";', file_input)
# send file:
file_input.send_keys("C:\Users\nicolas\Documents\CT\Séance_du_Lundi_15_février.pdf")

(cf This SO answer)

Interact with Windows file upload dialog (Windows and Python only)

You can directly handle the Windows dialog box using the Pywinauto module (the window has to be visible, not hidden).

import pywinauto

def (Name_of_File):
    app = pywinauto.application.Application()
    mainWindow = app['Envoi du fichier'] # main windows' title
    ctrl=mainWindow['Edit'] 
    mainWindow.SetFocus()
    ctrl.ClickInput()
    ctrl.TypeKeys(Name_of_File)
    ctrlBis = mainWindow['Ouvrir'] # open file button
    ctrlBis.ClickInput()

""" example:
("C:\Users\nicolas\Documents\CT\Séance_du_Lundi_7_mars.pdf")
"""

Windows’ titles are inside square brackets. You can easily get them (and other windows’ attributes) using tools like SWAPY.



Source link https://sqa.stackexchange.com/questions/34848/some-files-path-in-excel-sheet-that-path-need-to-pass-in-file-upload-text-and-c

LEAVE A REPLY

Please enter your comment!
Please enter your name here