Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

Upload file using Python + Selenium

So, I have input file field like:

<input type="file" layout="row" layout-align="start center" ng-controller="UploadController as upload" ngf-select="upload.uploadFile($files)" multiple="multiple" accept="image/jpeg, image/png, image/gif, application/pdf, video/mp4, video/quicktime, text/csv, application/excel, application/vnd.ms-excel, application/x-excel, application/x-msexcel, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, .csv, .xls, .xlsx, application/octet-stream, audio/x-ms-wma, audio/mp3, audio/ogg, audio/wav, audio/aac, .aac, .wma" md-ink-ripple="md-ink-ripple">

I need to upload some jpg or png using python. Solution that are present are not working for me.

My code looks like this:

def upload_file(self)
    self.find_element(MyPageLocators, BUTTON_UPLOAD_FILE).send_keys(os.getcwd() + "./data/test.jpg")

I define upload button like this:

BUTTON_UPLOAD_FILE = (By.CSS_SELECTOR, 'input[type="file]')

Steps file looks like this:

@when ('I upload file to my files')
def upload_file(context):
    page = mypage(context)
    page.upload_file()

"test.jpg" located in my tests folder in subfolder data. But my test is not working. What should I fix there?

Comments