【问题标题】:How to handle the error message without getting the error in Jenkins result如何在 Jenkins 结果中不出现错误的情况下处理错误消息
【发布时间】:2021-02-12 11:25:31
【问题描述】:

下面的代码抛出'stale element reference: element is not attach to the page document'

如何处理错误信息并将结果显示为通过

Action- 下面的代码是在另一张图片中添加一张图片(可以是一张或多张)

public void click_on_the_Add_to_collection_button_displaying_down_below_the_assert()  {



    List<WebElement> all_colection = driver.findElements(By.xpath("//li//button[@class='icon-button ' and @title='Add To Collection']"));

    int collection_size = all_colection.size();

    System.out.println("the collection size is " + collection_size);

    Random ran = new Random();

    

    all_colection.get(collection_size - 1).click();


    crate_new_colection.sendKeys("newcollection#1");


}
 

【问题讨论】:

    标签: java selenium cucumber


    【解决方案1】:

    try..catch 包裹,如下所示:

    public void click_on_the_Add_to_collection_button_displaying_down_below_the_assert()  {
        try{
            List<WebElement> all_colection = driver.findElements(By.xpath("//li//button[@class='icon-button ' and @title='Add To Collection']"));
            int collection_size = all_colection.size();
            System.out.println("the collection size is " + collection_size);
            Random ran = new Random();
            all_colection.get(collection_size - 1).click();
            crate_new_colection.sendKeys("newcollection#1");
        }catch (StaleElementReferenceException e){
            System.err.println("Skipping the exception. Do not let it get down stack.");
        }
    }
    

    P.S. - 我保持您的 snake case 不变,但请不要在 Java 中使用类似 Python 的代码样式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-21
      • 1970-01-01
      • 1970-01-01
      • 2014-12-11
      • 1970-01-01
      • 2021-02-24
      相关资源
      最近更新 更多