[英]How to pass a file download selenium webdriver command through a function
I have written the code below to go to a particular website, select a list of values in a dropdown, and then download a file for each dropdown value using the webdriver.我已经将下面的代码写入 go 到特定网站,select 下拉列表中的值列表,然后使用 webdriver 下载每个下拉值的文件。
There are about 15 different values that I need to pass through (ex: //option[@value='39) and download the file for each value passed through.我需要传递大约 15 个不同的值(例如://option[@value='39)并为传递的每个值下载文件。
Is there a way to create a function of the below and then a loop to send each of the 15 values one by one through that function?有没有办法创建下面的 function,然后循环通过 function 一个一个地发送 15 个值中的每一个?
driver.find_element(By.XPATH, "//option[@value='39']").click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "UpdateButton"))).click()
WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.CLASS_NAME, "DownloadButton"))).click()
Thanks谢谢
You can use the built-in range()
function.您可以使用内置的
range()
function。
For example, create a function to download the files:例如创建一个function来下载文件:
def download(value):
driver.find_element(By.XPATH, f"//option[@value='{value}']").click()
and then call the function 10 times using range
:然后使用
range
调用 function 10 次:
for i in range(1, 11):
download(i)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.