亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

合并兩個 WebElements 列表

合并兩個 WebElements 列表

長風秋雁 2023-05-24 15:28:51
無法打印合并列表中的值,因為它向我拋出空值!List<WebElement> DateTime2 = driver.findElements(By.xpath(""));driver.findElement(By.xpath("")).click();List<WebElement> DateTime3 = driver.findElements(By.xpath(""));List<WebElement> DateTime = new ArrayList<>(DateTime2);DateTime.addAll(DateTime3);Thread.sleep(2000);System.out.println("This is for testing the list " + DateTime.get(2).getText());System.out.println("This is for testing the list " + DateTime.get(30).getText());我希望輸出打印日期和時間
查看完整描述

1 回答

?
蕭十郎

TA貢獻1815條經驗 獲得超13個贊

這是我使用的一些代碼的示例(盡管我為此示例稍微更改了它。這通常是擴展另一個類的一部分。)


int sanitycount= 0;

int ec_Timeout = 10; //seconds to wait for list... 

    public void RunAction(WebDriver driver, String in_xpath)

    {

                  try

      {

        wait = new WebDriverWait(driver, ec_Timeout);

        List<WebElement> found_elements = new ArrayList<>();

        found_elements = wait.until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.xpath(in_xpath)));


        if (!found_elements.isEmpty())

        {

        // store this array, return an array from function

        // or loop through array and add items to more global array..

        }


       }

       catch (Exception e)

       {

       if (e.getClass().getCanonicalName().equals("org.openqa.selenium.StaleElementReferenceException"))

         {

         //need to do it again, not finished loading

         System.out.println("*****************Stale caught-redoing");

         sanitycount++;

         if (sanitycount<ec_Timeout * 2)

         {

         RunAction(driver, in_xpath);

         }

      System.out.println (e.toString());

      }

      else

      {

      System.out.println (e.toString());

      }

    }

  }

RunAction(your_driver, your_xpath); 

//set sanitycount back to zero if you run again...


查看完整回答
反對 回復 2023-05-24
  • 1 回答
  • 0 關注
  • 169 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號