【求助】关于selenium在IE8浏览器下运行失败,Could not start a new session

ganzhouguo 2013-03-28 02:03:00
求助有用过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 [http://localhost:35700/status] 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

也不知道是为什么,查询许久未果,求大神帮忙指出问题~~感激不尽
...全文
3494 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
chengsuchao 2015-05-13
  • 打赏
  • 举报
回复
这个是在官网下载的
quelly 2015-02-12
  • 打赏
  • 举报
回复
System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");在哪里修改?
他们叫我斌哥 2014-08-28
  • 打赏
  • 举报
回复
iexploredriver这个东西怎么得到?
ganzhouguo 2013-03-28
  • 打赏
  • 举报
回复
It worked!So kind of you!刚开始捯饬这东西,只是从网上找了个简单的例子跑跑,我想我还没弄清楚它的工作原理,掩面思过。。。 你说的对的,因为selenium无法直接启动IE,所以需要借助IEDriver,我还注意到我代码中有错误,应该是System.setProperty("webdriver.ie.driver","C:\\Program Files\\Internet Explorer\\IEDriverServer.exe");修改后OK了。 Thank you so much!
  • 打赏
  • 举报
回复
You will need InternetExplorer driver executable on your system. So download it from the hinted source (http://code.google.com/p/selenium/downloads/list) unpack it and place somewhere you can find it. In my example, I will assume you will place it to C:\Selenium\iexploredriver.exe Then you have to set it up in the system. Here is the Java code pasted from my Selenium project: File file = new File("C:/Selenium/iexploredriver.exe"); System.setProperty("webdriver.ie.driver", file.getAbsolutePath()); WebDriver driver = new InternetExplorerDriver(); 要先下载一个iexploredriver才行。

58,454

社区成员

发帖
与我相关
我的任务
社区描述
Java Eclipse
社区管理员
  • Eclipse
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧