关于selenium2如何在mac下正常启动浏览器的问题

  最近在学习selenium2,平时学习都是在windows虚拟机中,因为自己的电脑是mac,所以想尝试在mac下运行脚本,但是在尝试之后发现浏览器都难以启动,一下是我的代码:

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class testEnvironment {
	public static void main(String[] args) {
		myChrome();
	}
	
	
	public static void startFirefox(){
		WebDriver driver = new FirefoxDriver();
		driver.manage().window().maximize();
		driver.navigate().to("http://www.baidu.com");
		
	}
	public static void myChrome(){
		System.setProperty("webdriver.chrome.driver", "files/chromedriver")
		WebDriver driver = new ChromeDriver();
		driver.navigate().to("http://www.baidu.com");
		driver.manage().window().maximize();
	}
}

   首先说火狐浏览器启动出现的问题,调用启动火狐浏览器的方法后浏览器可以正常打开,但是打开后却未打开url,并且控制台报错,日志如下:

org.openqa.selenium.firefox.NotConnectedException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms.

  然后我再说说启动谷歌浏览器遇到的问题,调用启动谷歌浏览器的方法后,浏览器都不打开,直接控制台报错,日志简要如下:

Exception in thread "main" org.openqa.selenium.remote.UnreachableBrowserException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.

  这里要对于谷歌浏览器中调用的驱动做下简要说明,这个驱动是我在Google官网下载的mac版本的,下载地址如下:

  http://chromedriver.storage.googleapis.com/index.html

  在这里希望各位测试大神们能根据我上面反馈的问题,帮忙分析下怎么解决在mac下启动浏览器的问题,谢谢啦~~

 

posted @ 2016-03-09 15:29  lyfdeaia  阅读(476)  评论(0)    收藏  举报