我通过更改watir-webdriver的配置文件出错了。我使用以下代码禁用在firefox中加载图像:
profile = Selenium::WebDriver::Firefox::Profile.from_name "default"
profile['permissions.default.image'] = 2
browser = Watir::Browser.new :firefox, :profile => profile
出现此错误消息:
/var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/remote/w3c_bridge.rb:80:in `initialize': unknown option: {:profile=>#<Selenium::WebDriver::Firefox::Profile:0x00000000e90700 @model="/home/amvisor/.mozilla/firefox/9ud9suhs.default", @native_events=false, @secure_ssl=false, @untrusted_issuer=true, @load_no_focus_lib=false, @additional_prefs={"permissions.default.image"=>2}, @extensions={}>} (ArgumentError)
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/firefox/w3c_bridge.rb:34:in `initialize'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/common/driver.rb:49:in `new'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver/common/driver.rb:49:in `for'
from /var/lib/gems/2.3.0/gems/selenium-webdriver-3.0.0/lib/selenium/webdriver.rb:82:in `for'
from /var/lib/gems/2.3.0/gems/watir-webdriver-0.9.3/lib/watir-webdriver/browser.rb:46:in `initialize'
from xxx.rb:38:in `new'
from xxx.rb:38:in `<main>'
意味着什么:
initialize: unknown option: {:Profile
有人可以帮忙吗? 谢谢!
答案 0 :(得分:3)
这适用于使用Firefox 48 +的现有Firefox配置文件:
package test1;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URL;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
public class check1 extends JFrame implements ActionListener{
JEditorPane jep;
JScrollPane scroll;
JPanel p,p1;
JButton b,b1,b2,b3;
Dimension d;
String url;
public check1() {
d = new Dimension(500, 1500);
b = new JButton("Click ME");
b.addActionListener(this);
b1 = new JButton("Click ME");
b2 = new JButton("Click ME");
//b2.setBounds(0, 100, 70, 40);
b3 = new JButton("Click ME");
//b3.setBounds(0, 150, 70, 40);
p = new JPanel();
p.setLayout(new FlowLayout());
p.add(b);
p1 = new JPanel();
p1.setLayout(new GridLayout(4, 2, 1, 1));
p1.add(b1,0,0);
p1.add(b2,0,1);
p1.add(b3,2,0);
p1.setVisible(false);
try {
jep = new JEditorPane("file:///C:/Users/Chinmay/workspace/project1/src/page1.html");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
jep.setEditable(true);
scroll = new JScrollPane(jep);
setLayout(new BorderLayout());
getContentPane().add(p,BorderLayout.NORTH);
getContentPane().add(p1,BorderLayout.WEST);
getContentPane().add(scroll,BorderLayout.CENTER);
setSize(1000, 800);
setVisible(true);
setLocationRelativeTo(null);
}
public static void main(String args[])
{
new check1().setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(b))
{
p1.setVisible(true);
}
else if(e.getSource().equals(b1))
{
url ="file:///C:/Users/Chinmay/workspace/project1/src/page.html";
try {
jep.setPage(url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else if(e.getSource().equals(b2))
{
url ="file:///C:/Users/Chinmay/workspace/project1/src/page1.html";
try {
jep.setPage(url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
else if(e.getSource().equals(b3))
{
url ="file:///C:/Users/Chinmay/workspace/project1/src/page2.html";
try {
jep.setPage(url);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
}
Ruby绑定尚未完全支持新geckodriver中旧版Firefox驱动程序的Firefox配置文件的所有功能。如果您需要这些附加功能,可以使用Firefox&lt; 48(我建议安装扩展支持版本)并在功能中传递profile = Selenium::WebDriver::Zipper.zip('/path/to/profile/xxx.default')
caps = Remote::Capabilities.firefox(firefox_options: {profile: profile})
browser = Watir::Browser.new :firefox, desired_capabilities: caps
。