Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
等待Python+;硒+;火狐_Python_Python 3.x_Selenium_Firefox - Fatal编程技术网

等待Python+;硒+;火狐

等待Python+;硒+;火狐,python,python-3.x,selenium,firefox,Python,Python 3.x,Selenium,Firefox,我想在文件下载完成后立即关闭浏览器。我有下面的代码,但它没有关闭浏览器。我一定是哪里错了。请帮帮我 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'

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

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)
不支持导致循环永不退出的全局样式路径定义

您需要使用
glob.glob()
fnmatch

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


我已经为zip文件下载编写了一个下载方法,这可能会有所帮助。单击下载按钮后,将调用此方法并等待下载完成

def downloader() :
    print("File Download Started.......")
    sleep(60)
    while True:
        file = glob.glob(BASE_FILE_DIR+'*.zip.part')
        if file:
            print("Download Pending.......")
            sleep(60)
            continue
        else:
            print('File Downloaded')
            break

这正是我想要的,当文件下载在几秒钟到几分钟之间时,它非常有用。非常感谢你!