当前位置: 首页 > 知识库问答 >
问题:

列表的Selenium中的“StaleElementReferenceException”

水渊
2023-03-14

请你提出一些解决这个问题的方法好吗?谢谢

List<WebElement> orderID = new ArrayList<WebElement>();
List<WebElement> statusID = new ArrayList<WebElement>();

public void OrderandReleases()     
{
orderID = outboxpage.findtable(orderID);
util.pause("1");
statusID = outboxpage.findordernumber(statusID, orderID);
}

public List<WebElement> findOrderID(List<WebElement> orderID) {
WebElement table = driver.findElement(By.id("_kod7c3"));      
List<WebElement> allRows = table.findElements(By.tagName("tr"));

//And iterate over them, getting the cells 
for (int i = 1; i < allRows.size(); i++) {
 List<WebElement> alltd = allRows.get(i).findElements(By.tagName("td"));
                for (int j = 0; j < alltd.size(); j++) {
                    if (j == 1) {
                        orderID.add(alltd.get(j));
                        continue;
                    }
                }
            }
              return orderID;
}

public List<WebElement> clickonIndividualOrderID(List<WebElement> 
statusID,List<WebElement> orderID){
    for (int i = 0; i < orderID.size(); i++) {  
    WebElement table = driver.findElement(By.id("_kod7c3")); 
        if (table.isDisplayed()) {
            System.out.println("Clicking on 
order="+orderID.get(i).getText()); -> //first time it will run fine , second time when it loops back it will thow the execption StaleElementReferenceException here
            orderID.get(i).click(); -> //it is clicking on a order link and it will take me to next page
            driver.findElement(By.id("_jxndro")).click();

            WebElement table2 = driver.findElement(By.xpath("//*
[@id=\"_mfb\"]"));  
            List<WebElement> allRows2 = 
table2.findElements(By.tagName("tr"));

            String col = "";
            for (int j = 1; j < allRows2.size(); j++) {
                List<WebElement> alltd2 = 
allRows2.get(j).findElements(By.tagName("td"));
                int flag = 0;
                for (int k = 0; k < alltd2.size(); k++) {
                    col = alltd2.get(k).getText().toString().trim();
                    System.out.println(col);
                    if (col.equals("Failed")||col.contains("FE-")) {
                        statusID.add(alltd2.get(++k));
                        driver.findElement(By.id("_uvsub")).click(); --> // it will take me back to the first page
                        flag =1;
                        break;
                    }
                }
                 if(flag==1)
                        break;
            }
        }
    }
    return statusID;
}

共有1个答案

锺离飞尘
2023-03-14

当您发现任何第三方代码的特定异常时,您应该在所述代码的官方文档中查找信息(如果可用)。您可以在这里找到有关“StaleElementReferenceException”的信息

在所述页面中,您会发现

最常见的原因是元素所在的页面已被刷新,或者用户已导航到另一个页面。

 类似资料:
  • 我是硒的新手,我试图从下拉列表中选择一个选项。下拉列表的超文本标记语言如下: WebElement的是: 我已经尝试了几乎所有的方法,我可以在互联网上找到,但没有任何效果。我试图使用类,包装了,但它抛出了一个异常。 我试图丢失列表中的所有选项,但在这种情况下得到了异常应该有标签,但它有。我需要使用作为findelements的标识符。 请帮我解决这个问题。

  • 一、 Commands (命令) Action 对当前状态进行操作 失败时,停止测试 Assertion 校验是否有产生正确的值 Element Locators 指定HTML中的某元素 Patterns 用于模式匹配 1. Element Locators (元素定位器) id=id id locator 指定HTML中的唯一id的元素 name=name name locator指定 HTML

  • rank ▲ ✰ vote url 45 441 233 760 url 合并列表中的列表 可能重复的问题: Flattening a shallow list in Python Comprehension for flattening a sequence of sequences? 我想是不是有更好的方法 我可以用一个循环来做,但是除了这样做还有什么更cool的用一行来做的方法?我用redu

  • 问题内容: 蟒蛇 我有一个清单清单。喜欢 我想计算每个列表在主列表中出现了多少次。 我的输出应该像 问题答案: 只需使用来自:

  • 问题内容: 我有一个 清单清单 : 我想转换为一个 集合, 即删除重复列表并从中创建一个仅包含 唯一 列表的新列表。 在上述情况下,所需答案将是 但是当我这样做时,它给了我错误 TypeError:无法散列的类型:“列表” 你能解决我的问题吗?提前致谢! 问题答案: 由于列表是可变的,因此不能进行哈希处理。最好的选择是将它们转换为元组并形成一个集合,像这样 我们一次遍历一个列表,将其转换为一个元组

  • 有人能帮我找到这个的xpath吗?提前谢谢。 HTML如下所示: 鼠标悬停时属性的值正在更改,如下所示: 以下是选项的检查代码: