Newbee在这里 . 请解释 why this issue happened and how to fix it.
Error:
“C:\ Program Files(x86)\ Python36-32 \ python.exe”C:/Users/Vivek-Pc/PycharmProjects/tryOutSeries/searchTryout2.py在以下情况中忽略异常:> Traceback(最近一次调用最后一次):文件“ C:\ Program Files(x86)\ Python36-32 \ lib \ site-packages \ selenium \ webdriver \ common \ service.py“,第173行,在del文件”C:\ Program Files(x86)\ Python36-32 \ lib \ site-packages \ selenium \ webdriver \ common \ service.py“,第149行,在停止文件”C:\ Program Files(x86)\ Python36-32 \ lib \ site-packages \ selenium \ webdriver \ common \ service .py“,第120行,在send_remote_shutdown_command中ImportError:sys.meta_path为None,Python可能正在关闭进程以退出代码0结束
Code Used:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver_path = "c:\Program Files (x86)\Python36-32\Lib\site-packages\selenium\webdriver\chrome\chromedriver"
b_obj = webdriver.Chrome(driver_path)
b_obj.implicitly_wait(15)
b_obj.maximize_window()
b_obj.get('http://stackoverflow.com/')
search_box = b_obj.find_element_by_name('q')
search_box.clear()
search_box.send_keys("Selenium")
search_box.submit()
b_obj.close()
Environment Info:
Windows,Selenium,Python,Chrome(chromedriver.exe)和PyCharm
1 回答
我使用Python 3.6,Selenium 3.0.2和ChromeDriver 2.27(此时最新的一切)重现了同样的错误 .
问题似乎发生在Python selenium webdriver在显式关闭驱动程序时或者脚本执行简单结束(并且
__del__
方法被执行)时尝试stop the chromedriver service时 .向Python / Selenium github问题跟踪器报告了这个问题:
Workaround:
我发现使用
driver.quit()
而不是driver.close()
有助于解决问题 .