|
本帖最后由 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 [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
复制代码 也不知道是为什么,查询许久未果,求大神帮忙指出问题~~感激不尽 |
|