I am trying to select all files with python selenium.
dir = os.chdir("C:\\Users\\adam\\OneDrive - Wheelers Lane Technology College\\Pictures\\ama")
for file in glob.glob("*.jpg"):
print(file)
driver.find_element_by_xpath('//*[@id="upl-fileInp"]').send_keys(file)
This is what I have and it lists all the files in a directory, but I don't know how to select it.
In order to upload a file with Selenium you have to send it absolute path including the file name to the input
element.
Something like this
for file in glob.glob("C:\\Users\\adam\\OneDrive - Wheelers Lane Technology College\\Pictures\\ama\\*.jpg"):
driver.find_element_by_xpath('//input[@type="file"]').send_keys(file)
To select elements by clicking on them, you use Javascript's click()
files = driver.find_element_by_xpath('//*[@id="upl-fileInp"]').send_keys(file)
for element in files:
driver.execute_script("arguments[0].click();", element)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.