how to get an image's tooltip, which will only appear when we mouseover it. In Selenium

huangapple go评论90阅读模式
英文:

how to get an image's tooltip, which will only appear when we mouseover it. In Selenium

问题

我正在学习Selenium,并且想要在Selenium控制台上获取图像的工具提示。工具提示只会在鼠标悬停在图像上时出现。我尝试获取XPath并使用操作,但没有成功。

我正在使用的网站是:(https://mayexam.cpsatexam.org/certifications/),我正在寻找三个圆形徽标图像的工具提示。

String xpathTooltip1 = "//*[@id=\"tippy-1\"]/div/div[2]";

String img2 = "//*[@id=\"eael-section-tooltip-bf4f6d6\"]/div/div/img";

WebElement toolTIP = driver.findElement(By.xpath(img2));
action.clickAndHold(toolTIP).moveByOffset(50, 0);
String actTooltip = driver.findElement(By.xpath(xpathTooltip1)).getText();
System.out.println("The tooltip is " + actTooltip);
英文:

I am learning Selenium, and i want to get the tooltip of the image printed on the selenium console,...the tooltip will only appear when we mouse over the image.. I tried to get the xpath and used actions.. but its not working..

         the website I am using is...(https://mayexam.cpsatexam.org/certifications/) the tooltip of the three round logo images is i am looking for

String xpathTooltip1 ="//*[@id="tippy-1"]/div/div[2]";

		String img2 = "//*[@id=\"eael-section-tooltip-bf4f6d6\"]/div/div/img";
		
		WebElement toolTIP = driver.findElement(By.xpath(img2));
		action.clickAndHold(toolTIP).moveByOffset(50, 0);
		String actTooltip = driver.findElement(By.xpath(xpathTooltip1)).getText();
		System.out.println("The tooltip  is " + actTooltip);

答案1

得分: 0

以下是已翻译的内容:

工具提示通常是标题属性的一部分。在这种情况下,工具提示位于具有类“tippy-content”的“div”标签中。

此代码将起作用。

String img2 = "//*[@id="eael-section-tooltip-bf4f6d6"]/div/div/img";
String xpathTooltip1 = "//div[@class='tippy-content']";

WebElement image= driver.findElement(By.xpath(img2));
Actions action = new Actions(driver);
action.moveToElement(image).perform();
String actTooltip = driver.findElement(By.xpath(xpathTooltip1)).getText();
System.out.println("The tooltip is " + actTooltip);

英文:

Tooltips are generally part of title attribute. In this case tooltip is in 'div' tag with class 'tippy-content',

This code will work.

String img2 = "//*[@id=\"eael-section-tooltip-bf4f6d6\"]/div/div/img";
String xpathTooltip1 = "//div[@class='tippy-content']";


WebElement image= driver.findElement(By.xpath(img2));
Actions action = new Actions(driver);
action.moveToElement(image).perform();
String actTooltip = driver.findElement(By.xpath(xpathTooltip1)).getText();
System.out.println("The tooltip  is " + actTooltip);

how to get an image's tooltip, which will only appear when we mouseover it. In Selenium

huangapple
  • 本文由 发表于 2020年8月8日 05:42:35
  • 转载请务必保留本文链接:https://go.coder-hub.com/63309485.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定