2015-12-23 48 views
1

關於我以前的question,我無法返回到Iframe模式關閉後的初始頁面。C#Selenium:無法返回初始頁面

我試圖用

driver.SwitchTo().DefaultContent(); 
string currentWindow = driver.CurrentWindowHandle; //called before iframe modal popup window is called to open. 
driver.SwitchTo().Window(currentWindow); 

,但沒有這樣做,收到錯誤:----> OpenQA.Selenium.StaleElementReferenceException:元素在緩存中沒有發現 - 也許是頁面已經改變,因爲它看起來向上。

預期結果:按鈕應該獲得點擊

實際結果:收到一條錯誤消息。

回答

0

問題解決

string currentWindow = driver.CurrentWindowHandle; 
driver.SwitchTo().Window(currentWindow); 
driver.FindElement(By.XPath("@XpathLocation")).Click(); 

它不能識別標識,甚至類,所以我加Xpath with calling curent window handler和它的工作。