我如何使用解压后的扩展程序启动Chrome? [英] How can I launch Chrome with an unpacked extension?

查看:456
本文介绍了我如何使用解压后的扩展程序启动Chrome?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Selenium WebDriver来测试我正在开发的Google Chrome扩展程序。我注意到可以自定义 ChromeDriver 来向其启动的Chrome实例添加扩展程序。这可以通过使用 ChromeOptions AddExtension AddExtensions c> class。

I'm using Selenium WebDriver to test a Google Chrome extension I'm developing. I noticed that ChromeDriver can be customised to add extensions to the instance of Chrome that it launches. This can be achieved using the AddExtension and AddExtensions methods of the ChromeOptions class.

这些方法的文档表明它们需要扩展才能作为crx文件提供。由于开发扩展,所以我没有crx文件。我希望能够加载解压后的扩展,但我找不到一个方法来做到这一点。

The documentation for these methods indicates that they require extensions to be provided as crx files. Since I'm developing the extension, I don't have a crx file. I would like to be able to load the unpacked extension, but I couldn't find a method to do this.

我试着将扩展文件放在一个zip文件中,为 AddExtension 方法指定此值,但由于它不是crx文件,因此导致发生异常。我也尝试传入包含解压缩文件的目录,但是这产生了一个 FileNotFoundException

I tried putting the extension files in a zip file and specifying this for the AddExtension method, but this caused an exception to occur since it wasn't a crx file. I also tried passing in the directory containing the unpacked files, but this produced a FileNotFoundException.

我该怎么办这是什么?

推荐答案

我可以通过使用 AddArgument 方法直接将信息传递给Chrome。下面是它在C#中的样子:

I was able to achieve this by using the AddArgument method to directly pass the information to Chrome. Here's what it looks like in C#:

options = new ChromeOptions();
options.AddArgument("--load-extension=" + unpackedExtensionPath);

这篇关于我如何使用解压后的扩展程序启动Chrome?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆