Selenium Python quit()方法无法在命令行

时间:2018-04-27 00:32:35

标签: python selenium selenium-firefoxdriver

使用python 3.6.2和FF(geckodriver-v0.20.1-win64),我有一个try / except块设置来关闭任何异常的selenium,我期望关闭所有打开的FF浏览器的实例硒。我有这段代码:

    while 1:

        try:

            print(now() + "    [+] GETTING OBJECT...")

            browser.get(url)

            obj = browser.find_element_by_class_name('search_result_row')

            objID = browser.execute_script(
                'return document.getElementsByClassName( '
                '"search_result_row" )[0].children[1].innerText.trim()')

            print("\nObject " + objID + " received @ " + now())

            objDSC = browser.execute_script(
                'return document.getElementsByClassName( '
                '"search_result_row" )[0].children[2].innerText.trim()')

            print('\n' + objDSC)

            for type in objTypes:
                print("CHECKING IF OBJECT IS: " + type + "...")
                if type in objDSC:
                    print("OBJECT IS OF USEABLE TYPE.")
                else:
                    print("OBJECT IS NOT OF USEABLE TYPE.\n")

            time.sleep(5)

        except:

            while(browser):
                print('Quitting browser...')
                browser.quit()
                time.sleep(3)

            sys.exit(0)

当我使用“python filename.py”从命令提示符启动脚本时,我看到在任务管理器中启动了4x FF进程,但是在出现错误或SIGINT时,“退出浏览器......”只是按预期循环但是4x FF进程并没有结束(我已经等了好几分钟了)。我也在quit()方法之前尝试过browser.close()而没有运气。我不确定我错过了什么/做错了什么?

0 个答案:

没有答案