加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 这个错误意味着什么:陈旧元素引用:元素没有附加到页面文

发布时间:2020-12-15 08:24:03 所属栏目:百科 来源:网络整理
导读:在我的C#app中使用selenium web驱动程序,我收到此错误: OpenQA.Selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document 在这段代码中: IWebElement e = driver.FindElement(By.XPath(link_clic
在我的C#app中使用selenium web驱动程序,我收到此错误:

OpenQA.Selenium.StaleElementReferenceException: stale element
reference: element is not attached to the page document

在这段代码中:

IWebElement e = driver.FindElement(By.XPath(link_click),10);
e.Click();

错误行在e.Click()中,但这是一个在XPath指定的同一链接中成功执行但在最后一次尝试失败的过程!那么这个错误意味着什么以及如何解决它?

解决方法

这意味着要么在页面中更改元素,要么删除元素,在此链接 http://www.seleniumhq.org/exceptions/stale_element_reference.jsp中完全引用

解决这个问题的一种方法是,你可以进行重试,可能是类似的

bool staleElement = true; 
while(staleElement){
  try{
     driver.FindElement(By.XPath(link_click),10).Click();
     staleElement = false;

  } catch(StaleElementReferenceException e){
    staleElement = true;
  }
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读