能够使用watir-webdriver加载扩展启动Chrome [英] Ability to launch chrome with extensions loaded with watir-webdriver

查看:140
本文介绍了能够使用watir-webdriver加载扩展启动Chrome的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用watir-webdriver启动Chrome,但加载了特定的扩展名。我一直无法弄清楚如何在ruby中做到这一点。当我运行下面的代码时:



@browser = Watir :: Browser.new(:chrome,:switches =>%w [ load-extension =扩展名的文件路径])



我会收到以下消息:

现在我注意到奇怪的是双重路径。我不知道前半部分路径来自哪里(... Google \ Chrome \Application\21 ...)。后半部分是我在代码中指定的内容。当我点击确定时,它会启动浏览器(它会一直等到我做),但没有加载扩展。这个错误的奇怪之处在于该文件夹位置的manafest.json文件
(并且不是扩展问题)并且对我来说看起来很好。我可以正常启动浏览器(自动化之外),它会运行扩展。让我知道是否有更多您需要的信息。

解决方案

好的,我找出问题所在。我现在使用这行代码:

  @browser = Watir :: Browser.new:chrome,:switches => %w [ -  load-extension = ... / Chrome / User \ Data / Default / Extensions / geelfhphabnejjhdalkjhgipohgpdnoc / 0.9.7_0] 

看起来像不喜欢路径周围的引号。把它们拿出来,它推出了延期罚款。

I'm attempting to launch chrome using watir-webdriver but with a specific extension loaded. I haven't been able to figure out how to do this in ruby. When I run the following code

@browser = Watir::Browser.new(:chrome, :switches => %w[--load-extension="file path of the extension"])

I will get this message:

Now what I noticed was odd was the dual path. I'm not sure where the first half of the path is coming from ("...Google\Chrome\Application\21..."). The 2nd half of it is what I specified in the code. When I click OK it'll launch the browser (it will wait until I do) but without the extension loaded. What's odd about the error is the manafest.json file is in that folder location (and no it's not an extension issue) and looks fine to me. I can launch the browser normally (outside of the automation) and it'll run the extensions. Let me know if there's more information that you need.

解决方案

OK I figured out what the problem was. I am now using this line of code:

@browser = Watir::Browser.new :chrome, :switches => %w[--load-extension=.../Chrome/User\ Data/Default/Extensions/geelfhphabnejjhdalkjhgipohgpdnoc/0.9.7_0]

looks like it doesn't like the quotes around the path. Took those out and it launched the extension fine.

这篇关于能够使用watir-webdriver加载扩展启动Chrome的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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