【已解决】关于selenium在IE8浏览器下运行失败,Could not start a new session
本帖最后由 guoningiris 于 2013-3-28 16:06 编辑求助有用过selenium的童鞋们,我在eclipse下运行以下JAVA程序,调用firefox,访问www.baidu.com,输入文字搜索。这个脚本运行正常。package com.example.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class ExampleForFireFox{
/**
* @param args
*/
public static void main(String[] args) {
System.setProperty("webdriver.firefox.bin", "D:\\Program Files For Work\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com");
System.out.println("1 Page title is: " + driver.getTitle());
WebElement element = driver.findElement(By.id("kw"));
// 输入关键字
element.sendKeys("zTree");
element.submit();
(new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
public Boolean apply(WebDriver d) {
return d.getTitle().toLowerCase().endsWith("ztree");
}
});
System.out.println("2 Page title is: " + driver.getTitle());
//关闭浏览器
driver.quit();
}
}
但是当我把其中webdriver换成IEdriver的时候,运行就报错了,代码如下:package com.example.tests;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class ExampleForInternet {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\iexplore.exe");
System.out.println("InternetExplorerDriver opened");
WebDriver driver=new InternetExplorerDriver();
driver.get("http://www.baidu.com/");
System.out.println("InternetExplorerDriver opened"+driver.getTitle());
//WebElement element =driver.findElement(arg0)
WebElement element=driver.findElement(By.id("kw"));
element.sendKeys("你好!");
element.submit();
}
}报错信息如下: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.
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:548)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:216)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:201)
at org.openqa.selenium.ie.InternetExplorerDriver.setup(InternetExplorerDriver.java:105)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:51)
at com.example.tests.test.main(test.java:27)
Caused by: org.openqa.selenium.WebDriverException: Timed out waiting for driver server to start.
Build info: version: '2.31.0', revision: '1bd294d', time: '2013-02-27 20:53:56'
System info: os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.6.0_23'
Driver info: driver.version: InternetExplorerDriver
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:165)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:62)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:527)
... 5 more
Caused by: org.openqa.selenium.net.UrlChecker$TimeoutException: Timed out waiting for to be available after 20553 ms
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:104)
at org.openqa.selenium.remote.service.DriverService.start(DriverService.java:163)
... 7 more
Caused by: com.google.common.util.concurrent.UncheckedTimeoutException: java.util.concurrent.TimeoutException
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:143)
at org.openqa.selenium.net.UrlChecker.waitUntilAvailable(UrlChecker.java:79)
... 8 more
Caused by: java.util.concurrent.TimeoutException
at java.util.concurrent.FutureTask$Sync.innerGet(Unknown Source)
at java.util.concurrent.FutureTask.get(Unknown Source)
at com.google.common.util.concurrent.SimpleTimeLimiter.callWithTimeout(SimpleTimeLimiter.java:130)
... 9 more也不知道是为什么,查询许久未果,求大神帮忙指出问题~~感激不尽 你需要去搞个IEDriver 的jar包。。。比如说用的WebDriver 2.28, 下载个IEDriverServer_Win32_2.28.0.zip然后解压得到IEDriverServer.exe文件把这个文件放到IE 的安装目录中去
还有System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\iexplore.exe");这句话你照葫芦画瓢画的不对。。。。
应该这样写System.setProperty("webdriver.ie.driver", "C:/Program Files/Internet Explorer/IEDriverServer.exe") 我也遇到这个问题,按照上面说的,下载了IEDriverServer.exe 2.42.0的,但是运行程序后还是报一样的错误,我的机器是win7系统的,是不是IEDriver与win7不兼容啊
多谢,刚开始捯饬这东西,只是从网上找了个简单的例子跑跑,我想我还没弄清楚它的工作原理,掩面思过。。。按你的方法试了一下,It worked!接下来可以开始实践+学习了。
下面我贴一下自己解决这个问题的过程:
1、下载一个系统兼容的IEDriver,可以从这里下载(http://code.google.com/p/selenium/downloads/list),我下载了IEDriverServer_Win32_2.31.0.zip
2、解压,放在目录下,我放在了IE安装目录下(C:\Program Files\Internet Explorer)
3、修改代码,System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");
原因嘛,因为selenium无法直接启动IE,所以需要借助IEDriver,至于firefox不用,可能因为是selenium的原配吧。所以,不只IE,chrome浏览器也是需要借助驱动的,都可以在上面的网站下载到。
再一次感谢 joykao~
页:
[1]