c# - (扩展图标栏 - chrome 浏览器)我们可以通过 selenium web 驱动程序自动执行此开/关操作吗

标签 c# selenium selenium-webdriver c#-4.0 google-analytics

我在 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/

相关文章:

c# - 为什么我需要在泛型子类中重新声明类型约束

c# - 在 asp.net MVC4 应用程序中重新连接到 Servicestack session

c# - 如何通过 Selenium、ChromeDriver 和 GoogleChrome 打开默认 Chrome 配置文件

android - 使用 appium-android 滚动到页面末尾

selenium-webdriver - Selenium Grid : Error communicating with the remote browser. 它可能已经死了

c# - LINQ 到 Azure 搜索

c# - 作为实例变量的类组合

python - 从下拉列表中抓取值

python selenium headless chromedriver在前一天工作时没有加载整页,代码没有改变

java - Safari 中的 Selenium Java - 切换到新选项卡不起作用