如何禁用Chrome的自动更新时,运行 selenium ?

v09wglhw  于 2023-02-10  发布在  Go
关注(0)|答案(1)|浏览(142)

我有一个自动测试套件,它使用Selenium来控制特定版本的Chrome浏览器。但是Chrome浏览器会在测试运行之间尝试自我更新。如何防止Chrome浏览器自动更新?

ruoxqz4g

ruoxqz4g1#

删除Google Chrome二进制文件的写入权限似乎会阻止其自我更新,至少在macOS上是这样。
在Python中,你可以使用如下代码来实现这一点:

import subprocess

def remove_write_permissions(itempath: str) -> None:
    subprocess.run([
        'chmod',
        '-R',
        'a-w',
        itempath
    ], check=True, capture_output=True)

remove_write_permissions('/Applications/Google Chrome.app')

我只在macOS上测试过这段代码,它可能在Linux上也能用,但在Windows上可能不行。

相关问题