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

셋업 보이는 다음 분해 방법은 단지 driver.close 구성

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); 
} 

(). 셀레늄 2.14와 testNG Eclipse 플러그인을 사용하고 있습니다.

+0

또한 파이어 폭스와 IE 드라이버를 시도해 본 결과 같은 일이 발생합니다. 어떤 도움을 주셔서 감사합니다! :) – user1088166

답변

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을 추가해야합니다 url).

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"); 
} 
관련 문제