2011-12-20 72 views
1

我对硒很新,所以我无法在我的代码中发现问题。我使用的是一个webDriver支持的硒对象,它启动了驱动程序,但从不打开URL,驱动程序在一会儿之后才关闭。上次发生在我身上的只是因为我已经从URL中留下了“http”。那么这次是什么造成的呢?WebDriver没有打开URL

public void testImages() throws Exception { 
Selenium selenium = new WebDriverBackedSelenium(driver, "http://www.testsite.com/login"); 
System.out.println(selenium.getXpathCount("//img")); 
} 

的设置是这样的:

public void setUp() throws Exception { 
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User1\\Desktop\\chromedriver_win_16.0.902.0\\chromedriver.exe"); 
driver = new ChromeDriver(); 
    Thread.sleep(2000); 
} 

的删除方法只是由driver.close的()。 我使用硒2.14和testNG Eclipse插件。

+0

另外我试过Firefox和IE驱动程序,并发生同样的事情。我会很感激任何帮助! :) – user1088166 2011-12-20 15:24:42

回答

1

您可能需要执行以下操作

selenium.open("www.testsite.com/login");

退房来自硒网站上的这个例子:

// You may use any WebDriver implementation. Firefox is used here as an example 
WebDriver driver = new FirefoxDriver(); 

// A "base url", used by selenium to resolve relative URLs 
String baseUrl = "http://www.google.com"; 

// Create the Selenium implementation 
Selenium selenium = new WebDriverBackedSelenium(driver, baseUrl); 

// Perform actions with selenium 
selenium.open("http://www.google.com"); 
selenium.type("name=q", "cheese"); 
selenium.click("name=btnG"); 

// Get the underlying WebDriver implementation back. This will refer to the 
// same WebDriver instance as the "driver" variable above. 
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getUnderlyingWebDriver(); 

//Finally, close the browser. Call stop on the WebDriverBackedSelenium instance 
//instead of calling driver.quit(). Otherwise, the JVM will continue running after 
//the browser has been closed. 
selenium.stop(); 

link to selenium

0

您需要添加driver.get(网址)如下。

public void setUp() throws Exception { 
System.setProperty("webdriver.chrome.driver", "C:\\Users\\User1\\Desktop\\chromedriver_win_16.0.902.0\\chromedriver.exe"); 
driver = new ChromeDriver(); 
driver.get("http://www.testsite.com/login"); 
}