【问题标题】:how to get an image's tooltip, which will only appear when we mouseover it. In Selenium如何获取图像的工具提示,只有当我们将鼠标悬停时才会出现。在硒
【发布时间】:2020-08-07 21:42:35
【问题描述】:

我正在学习 Selenium,我想在 selenium 控制台上打印图像的工具提示,...只有当我们将鼠标悬停在图像上时才会出现工具提示。我试图获取 xpath 并使用了操作。 .但它不起作用..

         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);
        

【问题讨论】:

  • 无法访问网站https://mayexam.cpsatexam.org/certifications/
  • 你的img 标签中没有title 属性吗?
  • 不,不是...我试过...谢谢
  • @DebanjanB 很抱歉,他们更改了网址...我现在无法访问它

标签: javascript java selenium selenium-webdriver selenium-chromedriver


【解决方案1】:

工具提示通常是标题属性的一部分。在这种情况下,工具提示位于类“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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-10-30
    • 2020-02-08
    • 1970-01-01
    • 2021-05-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    相关资源
    最近更新 更多