首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用Java在工具提示中定位span元素

如何用Java在工具提示中定位span元素
EN

Stack Overflow用户
提问于 2017-05-18 10:21:31
回答 2查看 613关注 0票数 1

我在span标记中定位元素时遇到了问题。

它需要一个工具提示的一部分,当我把我的鼠标放在上面。

我将在下面的图片中向您展示:https://i.stack.imgur.com/b1qTg.jpg 来自工具提示的数据

当我把鼠标放在那个点上时,工具提示就会出现。我需要获得这些数据来验证Selenium中网页的文本。

我用xpath尝试过这段代码,但它不返回任何数据:

代码语言:javascript
复制
//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();

有什么办法能把这些数据放进去吗??非常感谢你的帮助!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-05-19 08:57:35

解决了点击点!

//我的代码WebElement元素=WebElement

代码语言:javascript
复制
    // Use action class to mouse hover on Text box field
    Actions action = new Actions(driver);
    action.click(element).build().perform();
票数 0
EN

Stack Overflow用户

发布于 2017-05-19 10:19:09

使用如下:

代码语言:javascript
复制
\\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")));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44045094

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档