2011-12-20 77 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"); 
}