[英]I would like to know how to select all files with selenium python
I am trying to select all files with python selenium.我正在尝试 select 所有文件与 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.这就是我所拥有的,它列出了一个目录中的所有文件,但我不知道如何 select 它。
In order to upload a file with Selenium you have to send it absolute path including the file name to the input
element.为了上传带有 Selenium 的文件,您必须将包含文件名的绝对路径发送到
input
元素。
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()要通过单击 select 个元素,您可以使用 Javascript 的 click()
files = driver.find_element_by_xpath('//*[@id="upl-fileInp"]').send_keys(file)
for element in files:
driver.execute_script("arguments[0].click();", element)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.