css - 获取 last-of-type 的实际第 nth-of-type 位置

标签 css selenium highcharts

所以这是我的问题。我想使用 Selenium 遍历 HighCharts 中折线图的每个点。我想出了一种从 path:nth-of-type(1) 到 path:last-of-type 的方法。但是,它是从右到左的,我希望它是从左到右的(我知道我很尖锐)。 因此,如果我能找到一种从 last-of-type 开始到 nth-of-type(1) 的方法,我会非常高兴。但是,我不知道如何获得 last-of-type 的等价 nth-of-type(position),以便每次循环时将其减 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;
    }

最佳答案

为此,您可以使用 findElements:

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

然后使用count向后迭代。

关于css - 获取 last-of-type 的实际第 nth-of-type 位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24147827/

相关文章:

linux - 未知错误 : DevToolsActivePort file doesn't exist error while executing Selenium UI test cases on ubuntu

java - 如何使用 selenium 单击仅存在 "::Before"标签的元素

javascript - 如何使用 highcharts 创建列字符,其中每列都有不同的颜色

javascript - jQuery 鼠标悬停忽略元素之间的空白空间

javascript - 单击带有 selenium 的 javascript 链接

css - 为什么 chrome 显示的渲染字体与计算字体系列不同?

javascript - Highcharts "Cannot read property ' toFront' 未定义”

javascript - Highcharts 的历史数据中不存在毫秒数据

javascript - 从 1 到 10 的 Onkeypress 数字验证

javascript - jQuery fadeToggle 导致表格边框出现