2016-03-31 27 views
0

我目前正在开发一个自动化项目,在那里我需要使用Ruby/Selenium来发现Web应用程序验证后返回给用户的特定http头文件。我能够自动完成网络应用程序;但是,当我尝试使用Chrome扩展程序时,浏览器返回以下错误:使用Selenium和Ruby自动化Chrome扩展

chrome-extension:// [extension address]中的网页可能暂时关闭,或者它可能已永久移动到新的Web地址。

看着这个之后,看起来Selenium网络驱动程序使用与我的常规Chrome配置文件不同的Chrome配置文件。因此,我想知道是否有人知道是否有办法告诉Selenium在加载扩展程序时使用我的常规Chrome配置文件,或者在运行时安装扩展程序并安装扩展程序。

到目前为止,我发现的大多数答案都是围绕Python和Java进行的。请让我知道我是否可以提供更多信息。

回答

1

要在Windows上使用默认配置运行Chrome浏览器:

require 'selenium-webdriver' 

switches = ['user-data-dir='+ENV['LOCALAPPDATA']+'\\Google\\Chrome\\User Data'] 
driver = Selenium::WebDriver.for :chrome, :switches => switches 

driver.navigate.to "https://www.google.co.uk" 

或者添加附加到创建的配置文件:

require 'selenium-webdriver' 

driver = Selenium::WebDriver.for :chrome, 
    :desired_capabilities => Selenium::WebDriver::Remote::Capabilities.chrome({ 
    'chromeOptions' => { 
     'extensions' => [ 
     Base64.strict_encode64(File.open('C:\\App\\extension.crx', 'rb').read) 
     ] 
    } 
    }) 

driver.navigate.to "https://www.google.co.uk" 
+0

这奏效了,谢谢! – CodePull