我在span标记中定位元素时遇到了问题。
它需要一个工具提示的一部分,当我把我的鼠标放在上面。
我将在下面的图片中向您展示:https://i.stack.imgur.com/b1qTg.jpg 来自工具提示的数据
当我把鼠标放在那个点上时,工具提示就会出现。我需要获得这些数据来验证Selenium中网页的文本。
我用xpath尝试过这段代码,但它不返回任何数据:
//dot of the highchart where I put my mouse to see the tooltip. Selenium Webdriver doesn't find it and it causes an error, it stops the execution here
WebElement element = driver.findElement(By.xpath(".//*[@id='highcharts-4']/svg/g[5]/g[2]/path[5]")); //dot's xpath
// Use action class to mouse hover on the dot
Actions action = new Actions(driver);
action.moveToElement(element).build().perform();
WebElement toolTipElement = driver.findElement(By.xpath(".//*[@id='highcharts-4']/div[1]/span")); //xpath of the shown tooltip
// To get the tool tip text
String toolTipText = toolTipElement.getText();有什么办法能把这些数据放进去吗??非常感谢你的帮助!
发布于 2017-05-19 08:57:35
解决了点击点!
//我的代码WebElement元素=WebElement
// Use action class to mouse hover on Text box field
Actions action = new Actions(driver);
action.click(element).build().perform();发布于 2017-05-19 10:19:09
使用如下:
\\first click the dot using your code:
Actions action = new Actions(driver);
action.click(element).build().perform();
\\then use following code to get your data :
System.out.println("First line of Tooltip" + driver.findElement(By.cssSelector("div > div.highcharts-tooltip > span span:nth-child(1) > b")));
System.out.println("Second line of Tooltip" + driver.findElement(By.cssSelector("div > div.highcharts-tooltip > span span:nth-child(2) > b")));https://stackoverflow.com/questions/44045094
复制相似问题