我正在使用Ruby 1.9.3p484和Watir-webdriver(0.8.0)以及用于Ubuntu的Firefox 41.0进行Web应用程序自动化。
我希望浏览器不加载任何图片。为此,我尝试将'permissions.default.image'firefox参数更改为2.
我尝试过以下代码:
import java.util.ArrayList;
import java.util.List;
abstract class Student {
private int StudentID;
public Student() {
}
public Student(int _studentId) {
this.StudentID = _studentId;
}
}
class PrimarySchoolStudent extends Student {
public PrimarySchoolStudent() {
}
public PrimarySchoolStudent(int _studentId) {
super(_studentId);
}
}
class HighSchoolStudent extends Student {
public HighSchoolStudent() {
}
public HighSchoolStudent(int _studentId) {
super(_studentId);
}
}
abstract class ClassRoom {
private List<Student> students;
public void enrollStudent(int studentId) {
if (students == null)
{
students = new ArrayList<Student>();
}
Student student = newStudent(studentId);
students.add(student);
}
abstract Student newStudent(int studentId);
}
class HighSchoolClassRoom extends ClassRoom {
@Override
Student newStudent(int studentId) {
return new HighSchoolStudent(studentId);
}
}
class PrimarySchoolClassRoom extends ClassRoom {
@Override
Student newStudent(int studentId) {
return new PrimarySchoolStudent(studentId);
}
}
public class RunCode {
public static void main(String[] args) {
ClassRoom cr_highSchool = new HighSchoolClassRoom();
cr_highSchool.enrollStudent(1234);
cr_highSchool.enrollStudent(5678);
cr_highSchool.enrollStudent(1938);
cr_highSchool.enrollStudent(7465);
}
}
但是,浏览器会继续加载图像。在about:config页面中,'permissions.default.image'仍然设置为1。
关于什么可能出错的任何想法?
答案 0 :(得分:1)
我不知道为什么,但如果我在Selenium类init中使用from_name
方法,那么您的代码工作正常:
profile = Selenium::WebDriver::Firefox::Profile.from_name "default"