2014-02-28 24 views
0

我想使用下面的代碼在框架中加載一個URL,但URL只是在主窗口中加載。使用Selenium在一個框架中加載一個URL#

 WebDriver.SwitchTo().DefaultContent(); 
     WebDriver.SwitchTo().Frame("mainContent").Navigate().GoToUrl(_baseUrl); 

任何想法如何將一個URL直接加載到一個框架?

+0

幀=的iframe加載在激活的幀鏈接的腳本。這背後的意圖是什麼?你想解決什麼問題? – Arran

+0

我正在爲使用頁面工廠頁面對象創建的頁面執行ExecuteLoad。該應用程序有一個僅包含導航和一個iframe的主窗口。內容頁面在「mainContent」iframe中加載。我試圖在iFrame中加載頁面而不需要導航。 – user3198015

+0

我認爲你將需要爲此使用'JavacriptExecutor'。 – Richard

回答

0

以下是使用scriptexecutor和腳本的方法。
激活要使用驅動程序加載的幀。

//Driver implements IJavaScriptExecutor, like 
// OpenQA.Selenium.IE.InternetExplorerDriver 
// that inherits OpenQA.Selenium.Remote.RemoteWebDriver 
// which implements implements IJavaScriptExecutor 
InternetExplorerDriver driver = new InternetExplorerDriver(@"."); 
driver.SwitchTo().DefaultContent(); 

執行,通過使用驅動器

string _baseUrl = "www.google.com"; 
// the script that should be executed 
string javascript = string.Format("window.location.href = \"{0}\";", _baseUrl); 
try 
{ 
    driver.ExecuteJavaScript<int>(javascript); 
} 
catch (NullReferenceException e) 
{ //not sure why a null reference exception is thrown} 
+0

您應該在答案中向代碼添加一些解釋。 – RyPeck

相關問題