英文:
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论