简体   繁体   English

我想知道如何 select 所有文件与 selenium python

[英]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.

相关问题 我想使用硒使用python选择框架 - I would like to use selenium to select a frame using python 我想知道如何在python中将ISO日期更改为UTC - I would like to know how to change an ISO date to UTC in python 您好,我想知道如何在python中使用Enum - Hello, I would like to know how to use Enum in python Python我想知道如何使用for循环编写(DictWriter) - Python i would like to know how to writerow with a for loop (DictWriter) 我想知道这在python中是否可行 - I would like to know if this is possible in python 我想将一个巨大的文件拆分为许多文件,并在所有拆分文件中添加标头。 使用python - I would like to split a huge file into many number of files with the header in all split files. Using python 如何将此列表转换为数据框? 我想知道如何在python中做到这一点? - How to turn this list into a data frame? I would like to know how to do this in python? 我想知道如何使用 Bot 框架 SDK 为 python 设置自适应卡的主机配置 - I would like to know how to set the host config of the adaptive card using Bot framework SDK for python 我想知道如何制作while循环? - I would like to know how can I make while loop? 我想知道如何将 map 字典的值列表设为 dataframe - I would like to know how to map dictionary with list of value to dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM