zoukankan      html  css  js  c++  java
  • Selenium webdriver Java firefox 路径设置问题

    问题: Cannot find firefox binary in PATH. Make sure firefox is installed.

    原因:selenium找不到Firefox浏览器。

    方法一:重新安装Firefox在默认路径下。

    方法二:直接用System.setProperty方法设置webdriver.firefox.bin的值 

    
    

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;

    
    

    public class FirefoxDirectory {
    WebDriver driver=null;

    
    

    @Before
    public void setUp() throws Exception {
    System.setProperty("webdriver.firefox.bin", "D:\firefox\firefox.exe");
    driver=new FirefoxDriver();
    driver.get("http://www.baidu.com");
    driver.manage().window().maximize();
    }

    
    

    @After
    public void tearDown() throws Exception {
    driver.quit();
    }

    
    

    @Test
    public void test() throws InterruptedException {
    //test content
    }
    }

     方法三:利用setCapability进行设置 

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.remote.DesiredCapabilities;
    
    public class FirefoxDirectory {
        WebDriver driver=null;
    
        @Before
        public void setUp() throws Exception {
            DesiredCapabilities ffcapability = DesiredCapabilities.firefox();
            ffcapability.setCapability("firefox_binary", "D:\firefox\firefox.exe");
            driver=new FirefoxDriver(ffcapability);
            driver.get("http://www.baidu.com");
            driver.manage().window().maximize();
        }
    
        @After
        public void tearDown() throws Exception {
            driver.quit();
        }
    
        @Test
        public void test() throws InterruptedException {
            //test content
        }
    }

     方法四:利用FirefoxBinary进行设置 

    import java.io.File;
    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.firefox.FirefoxBinary;
    import org.openqa.selenium.firefox.FirefoxDriver;
    
    public class FirefoxDirectory {
        WebDriver driver=null;
    
        @Before
        public void setUp() throws Exception {
            File file = new File("D:\firefox\firefox.exe");
            FirefoxBinary firefoxbin = new FirefoxBinary(file);
            driver=new FirefoxDriver(firefoxbin,null);
            driver.get("http://www.baidu.com");
            driver.manage().window().maximize();
        }
    
        @After
        public void tearDown() throws Exception {
            driver.quit();
        }
    
        @Test
        public void test() throws InterruptedException {
            //test content
        }
    }
  • 相关阅读:
    创龙TMS320C6748开发板串口和中断学习笔记
    RTL8195AM开发板使用
    CC3100BoosterPack和CC31XXEMUBOOST板子的测试
    利尔达NB-IOT的PSM和eDRX低功耗模式笔记
    【原创】大数据基础之Zookeeper(3)选举算法
    【原创】大数据基础之Zookeeper(2)源代码解析
    【原创】大数据基础之Zookeeper(1)介绍、安装及使用
    【原创】论码农的财富修养
    【原创】大叔案例分享(2)处理大批量数据时如何实现“高效”同时实现“断点续传”功能
    【原创】大数据基础之Spark(1)Spark Submit即Spark任务提交过程
  • 原文地址:https://www.cnblogs.com/miniren/p/5015397.html
Copyright © 2011-2022 走看看