I am trying to automate a few file uploads with selenium and python.
Everything works fine the first file upload but when i try to upload the second file it just does not work. It does not give me errors and when i rerun the script the first upload works fine. The website has a file upload like this:
<input class="upload-class" type="file" accept="image/*" aria-label="upload text">
I use something like this:
driver.find_element(By.XPATH,"//input[#class='upload-class']").send_keys("C:\\path\\to\\file.jpg")
Related
I'm trying to upload a file to a site. Everything is fine, but at the moment selenium tries to read data from tag, uploading suddenly stops.
The uploading progress bar html code is:
<div id="progressbar1" class="progressbar">
<div id="progresspercent1" class="progresspercent">5%</div>
</div>
and my code is:
bar_id = "progresspercent1"
WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, bar_id)))
print("PERCENT:" + driver.find_element(By.XPATH, bar_id).text)
I also tried accessing this tag:
<tr id="uploadfile1" title="Upload" uploadrowid="1" status="cancel">
</tr>
And I used its "status" attribute to check if the file is uploading or not, but I had the same problem again. And I also tried using get_attribute('innerHTML') method (for progress bar) but that doesn't work too.
EDIT:
This is how I start uploading:
driver.find_element(By.ID, "menu_upload").click()
frame = driver.find_element(By.XPATH, '//*[#id="uploader1"]')
driver.switch_to.frame(frame)
driver.find_element(By.ID,"fileupload").send_keys(<File Address>)
The first line opens the upload box frame. I just switch to the frame and then try to upload the file using the last line.
And right now I'm not doing anything after printing the percent. Later on I might create a loop to print the percent and when the file was uploaded, close the webdriver.
I would like to automatically download the zip files provided by Copernicus EMS mapping service.
The aim is to track the development of activations and always download the most recent vector zips.
The zips are free to use but before you can download them in the browser you have to hit a checkbox.
An example link looks like this:
https://emergency.copernicus.eu/mapping/download/197206/EMSR614_AOI01_GRA_PRODUCT_r1_VECTORS_v1_vector.zip
When I simply download the file using requests.get() I end up with a useless zip file .
zip_r = requests.get('https://emergency.copernicus.eu/mapping/download/197206/EMSR614_AOI01_GRA_PRODUCT_r1_VECTORS_v1_vector.zip', allow_redirects=True)
with open('saved_zip_file', 'wb') as zip_file:
zip_file.write(zip_r.content)
This is the code of the checkbox:
<div class="form-item form-type-checkbox form-item-confirmation">
<input type="checkbox" id="edit-confirmation" name="confirmation" value="1" class="form-checkbox required error"> <label class="option" for="edit-confirmation">Confirmation <span class="form-required" title="This field is required.">*</span></label>
<div class="description">Please confirm that you read and understood the above written disclaimer of liability.</div>
</div>
But I don't know how to change the value of the checkbox using requests.post() if this is possible at all.
I also checked this similar question before but could not figure out whether that would be helpful in my case and where I would get the cookie from: Python wget bypass checkbox before download
Thank you - any help/hints appreciated
B.
I am trying to upload a file from a specific path in Python.
video_path = 'C:\\Users\\x\\Desktop\\s.mp4'
self.driver.find_element_by_xpath(file_upload).send_keys(video_path)
This works, but it opens this:
I have tried several xpaths, including ones with the word 'input' or other. I tried using this: https://www.tutorialspoint.com/how-to-upload-file-with-selenium-python
Here is screenshot of all the xpaths:
<input type="file" name="Filedata"
button id="select-files-button" type=" (This is the button that press that opens the select file option.)
I'm using django for a small project and I would make users able to download a pdf that's already existed in media/doc/ path
so I wrote this code
with open('media/doc/document.pdf', 'r',encoding='latin1',errors='replace') as pdf:
response = FileResponse(pdf.read(), content_type='application/pdf')
response['Content-Disposition'] = 'inline;filename=some_file.pdf'
return response
but when the pdf file get downloaded it's shown pages empty btw I have already tried utf-8 encoding and doesn't work for me even this doesn't work for me
So How can I make pages visible?
The code you are trying that should work but if it is not working than i suggest that you can download pdf file with HTML code also.
<a class="btn btn-lg btn-primary" href="{{ obj.url }}" type="application/octet-stream .pdf" download="menu.pdf" target="_blank" role="button">Download a pdf file</a>
recently download attribute has added in HTML5 you can directly download file from HTML now no need to create extra view for that now.
you can see details Here
How can I click file upload page options with python selenium? I mean, I click this <input type="file" id="uploadfile"> with this code: driver.find_element_by_id("uploadfile").click()
then, a small window opens, this window's title is 'File Upload' and I want write on location input in this window. How can I do this? Thanks !
If the file upload option is an input tag and its type is file then you can directly upload the file using send_keys() method in Selenium
e.g.
driver.find_element_by_id("uploadfile").send_keys("D:\test\filename.extension")
Note :enter absolute location of your file