Python Selenium - Edge 的实例在调用 quit() 方法后仍然打开

Python Selenium - Instances of Edge still open after calling the quit() method

嗨,

from msedge.selenium_tools import Edge, EdgeOptions
from time import sleep

edge_options = EdgeOptions()
edge_options.use_chromium = True

with Edge(options=edge_options) as wd:
    wd.get('https://www.google.com')
    sleep(5)
    wd.quit()

我正在使用 Windows 10 中包含的 Edge 浏览器(版本 85.0.564.51)和匹配的 edgedriver。

每当我 运行 这段代码时,它 运行 没有错误,但在它终止后,一个 msedge.exe-Process 被留下 运行ning.
有时还会在注册表的 运行- 文件夹中添加一个条目,内容如下:

"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --type=service --enable-logging --log-level=0 --user-data-dir="C:\Users\my_user_name\AppData\Local\Temp\scoped_dir10028_1475876327" /prefetch:8

这指向临时目录中的一个文件夹,我认为应该在进程完成时将其删除,但由于进程未完成,它仍然存在。

scoped_dir 文件夹包含以下文件:

[3532:6176:0915/120323.266:WARNING:account_consistency_mode_manager.cc(196)] Desktop Identity Consistency cannot be enabled as no OAuth client ID and client secret have been configured.
[3700:268:0915/120325.975:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(107,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(102,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

[3700:8084:0915/120326.115:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(121,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(116,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

[3700:15952:0915/120326.481:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(225,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(220,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

[3700:18152:0915/120326.585:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(155,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(150,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(91,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(91,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(91,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(91,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(91,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(91,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

[3700:18404:0915/120326.630:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(131,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(126,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

[3700:11452:0915/120326.648:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(158,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(153,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

[3700:21892:0915/120326.667:WARNING:angle_platform_impl.cc(48)] compileToBinary(257): 
C:\fakepath(174,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll
C:\fakepath(169,1-13): warning X3557: loop only executes for 1 iteration(s), forcing loop to unroll

我也尝试添加 'silent' 选项,但这并没有改变结果。
我必须做什么才能关闭这个简单脚本生成的所有内容?

提前致谢

您可以试试下面的代码。我使用下面的代码,msedge.exe 的实例将在调用 quit() 后被杀死。请注意把代码中的路径改成你自己的:

from msedge.selenium_tools import Edge, EdgeOptions
from time import sleep

edge_options = EdgeOptions()
edge_options.use_chromium = True
edge_options.binary_location = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe"
driver = Edge(executable_path = r"your_path_to_webdriver\msedgedriver.exe", options = edge_options)

driver.get('https://www.google.com')
sleep(5)
driver.quit()

结果: