获得最后类型的实际第n个类型位置

时间:2014-06-10 17:57:37

标签: css selenium highcharts

所以这是我的问题。我想使用Selenium在HighCharts中循环遍历折线图的每个点。我想办法从路径开始:nth-​​of-type(1)到path:last-of-type。然而,它是从右到左,我希望它从左到右(我知道我是巅峰)。 因此,如果我能找到从最后一个类型到第n个类型(1)的方法,我会非常高兴。但是,我不知道如何获得最后一个类型的等效类型(位置),以便每次循环时将其减少1。

这是我到目前为止的代码(从右到左):

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;
    }

1 个答案:

答案 0 :(得分:0)

您可以使用findElements

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

然后使用count向后迭代。