CMD启动selenium

来源:互联网 发布:网络销售怎么聊客户 编辑:程序博客网 时间:2024/06/05 02:47

CMD命令  输入:java -jar        路径/selenium-server-standalone-2.43.1.jar

可以启动selenium服务

运行这段代码遇到的一个异常:

public static void main(String[] args) {
        DefaultSelenium selenium = new DefaultSelenium("localhost",4444,"*firefox","http://www.baidu.com");
        selenium.start();
        selenium.open("http://www.baidu.com");
        selenium.windowFocus();//该方法用于激活当前选中的窗口
        selenium.windowMaximize();//方法用于将当前选中的浏览器窗口最大化
        selenium.refresh();//相当于F5,刷新页面
        try{
            Thread.sleep(3000);
        }catch(InterruptedException e)
        {
            e.printStackTrace();
        }//刷新界面后,等待3秒钟
        selenium.close();//关闭界面
    }
运行该代码会报:

Failed to start new browser session: java.lang.RuntimeException: java.lang.RuntimeException: Firefox 3 could not be found in the path!
Please add the directory containing ''firefox.exe'' to your PATH environment
variable, or explicitly specify a path to Firefox 3 like this:
*firefox3 c:\blah\firefox.exe

这个异常是指你的Firefox没有装到默认路径,解决方法:

1、重新安装Firefox,安装到默认路径

2、修改代码

DefaultSelenium selenium = new DefaultSelenium("localhost",4444,"*firefox E:/Program Files/Mozilla Firefox/firefox.exe","http://www.baidu.com");

Firefox带上他的安装路径,这样这个异常就解决了。

0 0
原创粉丝点击