C# 测试失败,出现“错误”;元素引用是过时的;在Firefox中,但在chrome中传递相同的代码
在firefox中运行测试时,我收到以下错误C# 测试失败,出现“错误”;元素引用是过时的;在Firefox中,但在chrome中传递相同的代码,c#,selenium,firefox,C#,Selenium,Firefox,在firefox中运行测试时,我收到以下错误 “OpenQA.Selenium.StaleElementReferenceException:的元素引用已过时;元素不再附加到DOM,不在当前帧上下文中,或者文档已刷新” 同样的代码也适用于chrome 它在以下代码块中失败: public static string GetElementTextByXPath(string XPath, string expectedText = null) { string elementN
“OpenQA.Selenium.StaleElementReferenceException:的元素引用已过时;元素不再附加到DOM,不在当前帧上下文中,或者文档已刷新”
同样的代码也适用于chrome
它在以下代码块中失败:
public static string GetElementTextByXPath(string XPath, string expectedText = null)
{
string elementNotFound = FrameworkSettings.msgElementNotFound;
if (IsElementPresentByXpath_Continue(XPath))
{
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(Int32.Parse(FrameworkSettings.ImplicitWaitTimeout_Long)));
wait.Until((d) => { return d.FindElement(By.XPath(XPath)); });
ElementScrollIntoViewByXPath(XPath);
OutlineSelectedElement(driver.FindElement(By.XPath(XPath)), "get");
if (expectedText == null)
{
wait.Until((d) => { return !string.IsNullOrWhiteSpace(d.FindElement(By.XPath(XPath)).Text); });
}
else
{
wait.Until((d) => { return d.FindElement(By.XPath(XPath)).Text == expectedText; });
}
return driver.FindElement(By.XPath(XPath)).Text;
}
else
{
return elementNotFound;
}
}
哪一行抛出了错误?嗨,Christine,下面是OutlineSelectedElement(driver.FindElement(By.XPath(XPath)),“get”);