向 FirefoxProfile 添加扩展时出错

Error on adding extension to FirefoxProfile

经过搜索,我找到了一种通过 .FirefoxProfile() 向 Firefox 添加扩展的方法。但是,到处都提到相同的解决方案。

我不明白为什么我会遇到错误。这是代码:

 String firebugFilePath = "C:\FF_addons\firebug.xpi";
        FirefoxProfile profile = new FirefoxProfile();
        try {
            profile.addExtension(new File(firebugFilePath));
            // Add more FF addons if required 
        } catch (IOException err) {                
        }
        driver = new FirefoxDriver(profile);

我遇到的错误在第 4 行:incompatible types: com.gargoylesoftware.htmlunit.javascript.host.file.File cannot be converted to java.io.File

听起来你导入了错误的 File class.

改变你的

import com.gargoylesoftware.htmlunit.javascript.host.file.File

import java.io.File