详情介绍

以下是一个示例脚本:
python
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
替换为你的Chrome浏览器驱动路径
driver_path = "C:/path/to/chromedriver.exe"
替换为你的Chrome浏览器版本号
chrome_version = "100"
替换为你想要启用和禁用的插件名称
plugin_name = "your_plugin_name"
创建一个WebDriver实例
driver = webdriver.Chrome(executable_path=driver_path, options=webdriver.ChromeOptions())
循环遍历所有插件
for i in range(1, 11):
切换到Chrome浏览器
driver.execute_script("window.open('http://www.google.com');")
等待页面加载完成
time.sleep(2)
启用插件
driver.find_element_by_xpath("//*[@id='plugin-list']/div[3]/ul/li[{}]".format(i)).click()
driver.find_element_by_xpath("//*[@id='plugin-list']/div[3]/ul/li[{}]/a".format(i)).click()
禁用插件
driver.find_element_by_xpath("//*[@id='plugin-list']/div[3]/ul/li[{}]/a".format(i)).click()
关闭浏览器
driver.quit()
将上述代码保存为一个`.py`文件,例如`chrome_plugins.py`,然后在命令行中运行`python chrome_plugins.py`。这将启动一个Chrome浏览器窗口,并逐个启用和禁用指定的插件。请根据实际情况修改脚本中的参数。