请查看此页面:https://bitly.com/2wokiu4+
当鼠标
位于此蓝色图表上时,我想读取一些文本并将其与此页面
上的另一个值进行比较(点击
)
知道如何读取此值
吗?
我尝试通过 HTML
搜索它
最佳答案
下面的代码获取所有高度不为0的图表,计算每个图表的点击次数,汇总所有图表并与右上角的点击量进行比较。
WebDriverWait wait = new WebDriverWait(driver, 20);
Actions actions = new Actions(driver);
int clicks = Integer.valueOf(wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("info-wrapper--clicks-text"))).getText());
List<WebElement> charts = wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.cssSelector(".highcharts-series-group rect:not([height='0'])")));
AtomicInteger totalChartClicks = new AtomicInteger();
charts.forEach(webElement -> {
actions.moveToElement(webElement).perform();
int amount = Integer.valueOf(driver.findElement(By.cssSelector("div.highcharts-tooltip span:nth-of-type(2)")).getText().replace("Total Clicks ",""));
totalChartClicks.addAndGet(amount);
});
Assert.assertEquals(totalChartClicks.get(), clicks);
关于Java Selenium 读取 Java 脚本弹出值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52342300/