如何使用Selenium在Angular 7应用程序中提取工具提示文本 [英] How to extract the tooltip text within an Angular 7 application using Selenium

查看:110
本文介绍了如何使用Selenium在Angular 7应用程序中提取工具提示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过硒在angular7应用程序中阅读文本工具提示.但是获取文本返回空白,而javascript执行程序返回null.

I'm trying to read text tooltip in angular7 application via selenium. But get text is returning blank and javascript executor is returning null.

链接到我无法为其找到xpath的DOM图像

但是获取文本返回空白,而javascript执行程序返回null.

But get text is returning blank and javascript executor is returning null.

这将返回空白

driver().get("https://vmware.github.io/clarity/documentation/v0.12/tooltips");
Wait(3000);
System.out.println(driver().findElement(By.xpath("(//span[@class='tooltip-content'])[2]")).getText());

这将返回null

System.out.println(driver().findElement(By.xpath("(//span[@class='tooltip-content'])[2]")).getAttribute("value"));

String theTextIWant = ((JavascriptExecutor) driver()).executeScript("return arguments[0].innerHTML;",driver().findElement(By.xpath("(//span[@class='tooltip-content'])[2]")));

推荐答案

要提取工具提示文本,请在

To extract the tooltip text Lorem ipsum sit within the Angular7 Application using Selenium you have to:

  • 诱使 WebDriverWait 使所需的元素可见
  • 鼠标悬停元素.
  • 诱使 WebDriverWait 使所需的工具提示可见
  • 然后提取工具提示文本
  • 您可以使用以下解决方案:

  • Induce WebDriverWait for the desired element to be visible
  • Mouse Hover the element.
  • Induce WebDriverWait for the desired tooltip to be visible
  • Then extract the Tool Tip Text
  • You can use the following solution:

  • 代码块:

  • Code Block:

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Angular_ToolTip {

    public static void main(String[] args) {

        System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("start-maximized");
        //options.addArguments("disable-infobars");
        options.addArguments("--disable-extensions");
        WebDriver driver = new ChromeDriver(options);
        driver.get("https://vmware.github.io/clarity/documentation/v0.12/tooltips");
        new Actions(driver).moveToElement(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h6[text()='Small']//following::div[1]/a[@class='tooltip tooltip-sm']")))).build().perform();
        System.out.println(new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//h6[text()='Small']//following::div[1]/a[@class='tooltip tooltip-sm']//following::span[1]"))).getAttribute("innerHTML"));
    }
}

控制台输出:

Lorem ipsum sit

  • 浏览器快照:

  • Browser Snapshot:

    这篇关于如何使用Selenium在Angular 7应用程序中提取工具提示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆