我在 Chrome 浏览器上安装了 Goggle 分析调试器 ( https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna ),并在 Chrome 浏览器的右上角(扩展图标栏)上打开/关闭开关。我们可以通过 selenium Web 驱动程序自动执行此开/关操作吗?
有什么方法可以自动执行此开/关操作
最佳答案
下面是使用 pyautogui 的 Python 解决方案(我认为它类似于 autoit - 因此您也可以为您的特定语言扩展相同的解决方案)。
先决条件:
将扩展图像保存在项目文件夹中(在示例中,我将其保存在“autogui_ref_snaps”文件夹下,名称为“capture_full_screenshot.png”
Python:
需要进口
from selenium import webdriver
from selenium.webdriver import ChromeOptions
from Common_Methods.GenericMethods import *
import pyautogui #<== need this to click on extension
脚本:
options = ChromeOptions()
options.add_argument("--load-extension=" + r"C:\Users\supputuri\AppData\Local\Google\Chrome\User Data\Default\Extensions\fdpohaocaechififmbbbbbknoalclacl\5.1_0") #<== loading unpacked extension
driver = webdriver.Chrome(
executable_path=os.path.join(chrome_options=options)
url = "https://google.com/"
driver.get(url)
# get the extension box
extn = pyautogui.locateOnScreen(os.path.join(GenericMethods.get_full_path_to_folder('autogui_ref_snaps') + "/capture_full_screenshot.png"))
# click on extension
pyautogui.click(x=extn[0],y=extn[1],clicks=1,interval=0.0,button="left")
如果您正在加载扩展程序并且它在隐身模式下不可用,请按照我在 here 中的回答进行操作。启用它。
关于c# - (扩展图标栏 - chrome 浏览器)我们可以通过 selenium web 驱动程序自动执行此开/关操作吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50955826/