2015-12-23 50 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和它的工作。