gpt4 book ai didi

python - 在Python+Selenium+Firefox中等待下载完成

转载 作者:行者123 更新时间:2023-12-01 02:23:01 26 4
gpt4 key购买 nike

我想在文件下载完成后立即关闭浏览器。我有下面的代码,但它没有关闭浏览器。我一定是在某个地方错了。请帮助我。

driver.find_element_by_link_text("[Comma-Delimited Text (CSV)]").click()
while True:
if os.path.isfile('C:\\Python34\\*.part'):
time.sleep(10)
elif os.path.isfile('C:\\Python34\\*.csv'):
break
else:
time.sleep(10)


def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)

最佳答案

os.path.isfile() 不支持 glob 样式的路径定义,导致循环永远不会退出。

您需要使用glob.glob()fnmatch:

您还可以使用 watchdog 等模块监视目录中的更改:

关于python - 在Python+Selenium+Firefox中等待下载完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47759491/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com