Selenium webdriver firefox 路径设置问题
2015-12-03 10:45
489 查看
问题: Cannot find firefox binary in PATH. Make sure firefox is installed.
原因:selenium找不到Firefox浏览器。
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
}
}
原因: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 } }
相关文章推荐
- Go语言slice的那些坑
- Qt—样式表(setStyleSheet())
- iOS NSLayoutAttributeLeft与NSLayoutAttributeLeading的区别
- Win10/UWP开发:让你的App使用上扫描仪
- 14.9.4 Defragmenting a Table 整理表
- Qt创建函数注意事项
- sortDescriptorWithKey 进行时间排序
- Python核心数据类型(内置对象)—— 列表(list)
- 关于秘钥认证的问题
- Android Stduio统计项目的代码行数
- 关于串口通信时,接收方要0xAABB,发送方应该怎么发送
- 我的第一篇博客随笔:关于angularjs API的理解心得。angular.bind() angular.boostrap()
- C++ Error:C2011: 'struct' type redefinition
- Tomcat 常用配置
- winfrom读写txt文件值(短信猫)
- [前端设计]卡片式列表
- ORA-01767: UPDATE ...SET 表达式必须是子查询
- 隐藏标题栏之二 requestWindowFeature
- C-031.多级指针
- 字符串相同字符长度却不同?