2017-05-04 4 views
-1
ここ

は、コード断片である:最後の行でセレンJavaのクローム:古い例外

System.setProperty(Constants.WEBDRIVER_CHROME_DRIVER_PROP, Constants.WEBDRIVER_CHROME_DRIVER_PATH); 

    m_chromeWebdriver = new ChromeDriver(); 
    m_chromeWebdriver.get("mysite.org"); 

    WebElement arrowElement = m_chromeWebdriver.findElement(By.cssSelector(_ARROW_NEXT_DAY)); 
    arrowElement.click(); 

    WebElement elmMainTable = m_chromeWebdriver.findElement(By.className("table-main")); 

    List<WebElement> allRows = elmMainTable.findElements(By.tagName("tr")); 

    for (WebElement row : allRows) { 

     List<WebElement> cells = row.findElements(By.tagName("td")); 
     for (WebElement cell : cells) { 
      System.out.println(cell.getText()); 
     } 
    } 
    m_chromeWebdriver.quit(); 

私が手

「古い要素参照:要素がページ 文書に添付されていません」

例外。

どうすれば解決できますか? 私はChromdriver 2.2.9を使用します。

おかげ

+1

ループを介してリスト要素を反復処理しています。右 ? – NarendraR

+0

'elmNextDayArrow.click();'この行は何をしますか? – kushal

+0

@NarendraRajput私はしたいと思います... – dushkin

答えて

0

まあ、これはおそらく、完璧なソリューションではありませんとして - 少なくとも、それは私のために働いた...

私はこのような方法に関連するすべてのコードを配置:

private static void handleTable() { 

    for (int i = 1; i < 5; i++) { 

    try { 
     WebElement elmMainTable = m_chromeWebdriver.findElement(By.className("table-main")); 

     List<WebElement> allRows = elmMainTable.findElements(By.cssSelector(".table-main tr")); 

     for (WebElement row : allRows) { 

      List<WebElement> cells = row.findElements(By.tagName("td")); 

      for (WebElement cell : cells) { 

       System.out.print(cell.getText() + "\t"); 
      } 
      System.out.println(); 
     } 

    } catch (StaleElementReferenceException e) { 

     //e.printStackTrace(); 

     handleTable(); 
    } 

    return; 
} 

}

これは機能しました。これまでどおりに値5を変更することができます。