我收到语法错误。?

时间:2015-04-20 11:33:36

标签: java selenium-webdriver

package js_executor_test_selenium;

import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.JavascriptExecutor;
public class js_executor_test_selenium {

    public static void main(String[] args) {
        // TODO Auto-generated method stub


        FirefoxProfile profile = new FirefoxProfile();
        profile.addExtension(FILE C:\\Users\\pcs\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\pdsrgsl1.default\\extensions\\firessh@nightlight.ws\\chrome\\firessh.jar");

        FirefoxDriver d1 = new FirefoxDriver(profile);

            //d1.get("http://www.google.com");

            JavascriptExecutor js = (JavascriptExecutor) d1;
            String domain_name = (String)js.executeScript("return document.title");
            System.out.println(domain_name);




    }

}

//我想执行这个脚本,我用来调用firefox扩展。请任何人都可以建议。我想启动firefox实例,扩展名在开始时启动。

3 个答案:

答案 0 :(得分:1)

来自addExtension(java.io.File extensionToInstall)

您应该在File对象的引号中传递参数,并且该文件对象将传递给方法addExtension,如:

profile.addExtension(new File("C:\\Users\\pcs\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\pdsrgsl1.default\\extensions\\firessh@nightlight.ws\\chrome\\firessh.jar"));

答案 1 :(得分:0)

addExtension需要文件对象吗?
试试这个。

 profile.addExtension(new File("filepath"));

答案 2 :(得分:0)

下载the xpi file of the extension并在addExtension电话中使用该文件:

profile.addExtension(new File("path/to/downloaded/xpi/file"));