2011-12-20 48 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

答えて

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"); 
} 
関連する問題