I am trying to implement a tool that checks whether a website has a drag and drop file upload functionality. Specifically, if a website such as this has a drag and drop file upload functionality, my tool needs to return True.
I found this code this Python code which utilizes Selenium to upload a file from the local file system to a website with drag and drop. It needs an element_id
of the drag/drop area and the path of the file.
I updated this code to build my tool. Specifically, my code first retrieves all of the elements of the website and checks whether the file is droppable returns True
. However, it still returns True even though the some 'ids' given to the functions are not droppable. I want to get return True only if the given "id" uploads to the file to the webserver.
ids = driver.find_elements_by_xpath('//*[@id]')
for ii in ids:
all_ids.append(ii.get_attribute('id'))
#print(ii.get_attribute('id')) # id name as string
try:
dropzone = driver.find_element_by_id(ii.get_attribute('id'))
dropzone.drop_files("/Users/pythonSelenium/test.png")
return True
except:
continue
How can I fix that issue?