问题
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.
回答1:
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.
来源:https://stackoverflow.com/questions/12586751/ability-to-launch-chrome-with-extensions-loaded-with-watir-webdriver