所以这是我的问题。我想使用 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/