使用Selenium web驱动程序,无法拍摄显示工具提示文本的网页截图

使用Selenium web驱动程序,无法拍摄显示工具提示文本的网页截图,selenium,selenium-webdriver,tooltip,screenshot,webdriverwait,Selenium,Selenium Webdriver,Tooltip,Screenshot,Webdriverwait,我试图拍摄显示工具提示文本的网页截图,但我只能看到鼠标悬停后突出显示的WebElement文本,但在脚本执行期间,工具提示甚至没有显示在网页上 这是我试图执行的一段代码。需要帮助来找出我遗漏了什么 public static void main(String[] args) throws InterruptedException, IOException, AWTException { String URL = "https://www.rediff.com"; Sy

我试图拍摄显示工具提示文本的网页截图,但我只能看到鼠标悬停后突出显示的WebElement文本,但在脚本执行期间,工具提示甚至没有显示在网页上

这是我试图执行的一段代码。需要帮助来找出我遗漏了什么

 public static void main(String[] args) throws InterruptedException, IOException, AWTException  
   {
    String URL = "https://www.rediff.com";
    System.setProperty("webdriver.chrome.driver", "C:\\Users\\bhara\\eclipse-workspace\\Drivers\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();
    driver.get(URL);
    driver.manage().window().maximize();
    driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);

    String WebElementXpath = "//*[@class='mailicon']";

    String toolTipText ;
    WebElement ToolTipElement = driver.findElement(By.xpath(WebElementXpath));

    Actions act1 = new Actions(driver);


    act1.moveToElement(ToolTipElement).build().perform();

     Robot robot = new Robot();

     Point point;
     point = ToolTipElement.getLocation();
     int x = point.getX(); 
     int y = point.getY(); 
     robot.mouseMove(x,y);

     File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
     FileUtils.copyFile(scrFile, new File("screenshot.png"));

    System.out.println( ToolTipElement.getAttribute("title"));

}

我在您的代码块中没有看到任何这样的问题。但是,如果您观察WebElement的外观,请执行以下操作:

文本闪电般的免费电子邮件
标题
属性,而不是工具提示。因此,通过使用Actions类将鼠标悬停在元素上不会弹出窗口。但是,我做了一些小改动,并执行了代码以获得如下相同的结果:

  • 代码块:

    ChromeOptions options = new ChromeOptions();
    options.addArguments("start-maximized");
    options.setExperimentalOption("excludeSwitches", Collections.singletonList("enable-automation"));
    options.setExperimentalOption("useAutomationExtension", false);
    WebDriver driver = new ChromeDriver(options);
    driver.get("https://www.rediff.com/");
    new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[@class='mailicon']")))).build().perform();
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(scrFile, new File(".\\Screenshots\\Rediffmail.png"));
    System.out.println(driver.findElement(By.xpath("//a[@class='mailicon']")).getAttribute("title"));
    driver.quit();
    
  • 控制台输出:

    Lightning fast free email
    
  • 截图:


也许您只需要增加一个延迟?工具提示不会立即出现,谢谢您的回复!我在截屏前添加了Thread.sleep(3000)。我仍然没有看到网页上的工具提示文本。感谢您的回复。有没有办法让工具提示文本在运行屏幕时出现在屏幕上,就像我们手动将鼠标悬停在屏幕上并看到工具提示时一样?