问题描述
我正在尝试在Firefox上安装附加组件,但是无论如何我都无法实现。
<ListBox ItemsSource="{Binding TankItems}"
SelectedItem="{Binding SelectedTankItem}">
<ListBox.ItemContainerStyle>
<Style targettype="ListBoxItem">
<Setter Property="IsSelected"
Value="{Binding IsSelected,Mode=TwoWay}" />
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate DataType="{x:Type Contactviewmodel}">
<StackPanel>
<TextBlock Text="Test" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Border>
<TextBlock Text="{Binding displayPopup}" />
</Border>
我在这里做错了什么?浏览器无需安装任何插件即可访问URL。我可以从文件中手动安装加载项。
require 'capybara'
require 'selenium-webdriver'
Capybara.register_driver :selenium_proxy do |app|
desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox
options = Selenium::WebDriver::Firefox::Options.new
profile = Selenium::WebDriver::Firefox::Profile.new
# Here is the add-on I am trying to install.
profile.add_extension('/home/user/Downloads/try_xpath-1.3.5-fx.xpi')
options.profile = profile
Capybara::Selenium::Driver.new(app,{
browser: :firefox,desired_capabilities: desired_caps,options: options
})
end
browser = Capybara::Session.new(:selenium_proxy)
browser.visit 'https://google.com'
解决方法
好吧,既然还没有人回答,我将分享如何解决这个问题,以防您想安装扩展程序。
如果其他人有更好的答案,那么我可以接受他们的答案,所以如果您有更好的解决方案,请回答。
第一种方法
我只是在弄乱Firefox的配置文件文件夹,我发现可以使用只包含extensions
文件夹的现有配置文件文件夹。因此,我已经删除了要使用的配置文件文件夹中的所有其他文件/文件夹。
因此,基本步骤是:
- 创建Firefox配置文件或使用现有的配置文件。
- 使用具有相同配置文件的浏览器安装所需的附件。
- 关闭浏览器。
- 导航到同一Firefox配置文件文件夹,并删除该配置文件文件夹中的所有其他文件/文件夹。
- 然后在实例化
Selenium::WebDriver::Firefox::Profile
时使用该Firefox配置文件文件夹的路径,如下所示:
Capybara.register_driver :selenium_proxy do |app|
desired_caps = Selenium::WebDriver::Remote::Capabilities.firefox
options = Selenium::WebDriver::Firefox::Options.new
profile = Selenium::WebDriver::Firefox::Profile.new '/path/to/firefox/profile/folder/'
options.profile = profile
Capybara::Selenium::Driver.new(app,{
browser: :firefox,desired_capabilities: desired_caps,options: options
})
end
browser = Capybara::Session.new(:selenium_proxy)
browser.visit 'https://google.com'
我尝试创建一个名为profile
的文件夹,并在该文件夹内创建了另一个名为extensions
的文件夹,就像Firefox一样,并将所有我要上传的附件移动到extensions
文件夹,但是没有用。
我认为Firefox在安装插件时会更改插件文件,因此无法从their website下载插件并尝试在配置文件文件夹中使用它。这当然是我的猜测。
第二种方法
您也可以使用:
browser = Capybara::Session.new(:selenium_proxy)
browser.driver.browser.install_addon '/path/to/addon.xpi'
我知道这看起来很混乱,因此您可以停止使用Capybara
并直接使用selenium
,但是Capybara
也有一些很酷的方法。