2014-06-10 31 views
0

所以這是我的問題。我想使用Selenium循環遍歷HighCharts中的折線圖的每個點。我想出了一種從路徑開始的方式:nth-​​of-type(1)到path:last-of-type。然而,它從右到左,我很樂意從左到右(我知道我很憔悴)。因此,如果我能找到一種從最後一種類型到第n種類型(1)的方法,我會非常高興。但是,我不知道如何獲得最後類型的等價類型(位置),以便每次循環時減少1。
獲取最後一個類型的實際第n個類型的位置

這裏是我到目前爲止的代碼(從右到左的一個):

public static boolean isLastPoint(int series,WebDriver driver){ 
     if(series > 1){ 
      WebElement last = driver.findElement(By.cssSelector("g.highcharts-series-group > g:nth-of-type(2) > path:last-of-type")); 
      WebElement current = driver.findElement(By.cssSelector("g.highcharts-series-group > g:nth-of-type(2) > path:nth-of-type(" + (series) + ")")); 
      return last.equals(current); 
     } 
     else return false; 
    } 

public static void overview(WebDriver driver, boolean active) { 
     if(active){ 
      wait(driver,By.id("highcharts-0")); 
      WebElement chart0 = driver.findElement(By.id("highcharts-0")); 
      LineChart lc0 = new LineChart(driver,chart0); 
      int series = 1; 
      while(!isLastPoint(series-1,driver)){ 
       lc0.hoverOverLineChart1(series, ""); 
       series++; 
      } 
     }else return; 
    } 

回答

0

您可以使用findElements此:

int count = driver.findElements(By.cssSelector("g.highcharts-series-group > g:nth-of-type(2) > path:last-of-type")).size(); 

然後使用count來向後迭代。

+0

謝謝你,那就是我一直在尋找的! – Chiquelo

相關問題