【问题标题】:How to find tooltip text message that is <Strong><br> tag in java如何在java中找到 <Strong><br> 标签的工具提示文本消息
【发布时间】:2018-12-23 14:55:56
【问题描述】:
WebElement element= driver.findElement(By.id("jform_email-lbl"));
Actions mouseOver = new Actions(driver);
mouseOver.moveToElement(element).perform();
//String toolTipText = element.getText();
String toolTipElement = driver.findElement(By.id("jform_email-lbl")).getAttribute("title data-original-title");

它给了我null 的价值。

HTML:

<label id="jform_email-lbl" for="jform_email" class="hasTooltip required" title="" data-original-title="<strong>Email Address</strong><br />Please enter the email address associated with your User account.<br />A verification code will be sent to you. Once you have received the verification code, you will be able to choose a new password for your account."> 
    Email Address
    <span class="star">&nbsp;*</span>
</label>

【问题讨论】:

  • 你可以试试getAttribute("data-original-title");

标签: java selenium xpath tooltip webdriverwait


【解决方案1】:

试试innerText

String text=driver.findElement(By.xpath("//your locator")).getAttribute("innerText");

【讨论】:

    【解决方案2】:

    很遗憾,您提供的信息并不多。您可以使用By.TagName("Strong) 并使用By.TagName("br") 过滤它们。例如,根据您的 DOM,您可以通过搜索特定的 &lt;div&gt; 来改进这一点。

    【讨论】:

    • 请将此作为格式化的 html 代码附加到您的初始帖子中。谢谢。
    【解决方案3】:

    要提取 tooltip 文本消息,您需要诱导 WebDriverWait 以使所需的 元素可见,您可以使用以下解决方案:

    new Actions(driver).moveToElement(element).perform();
    String toolTipElement = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//label[@class='hasTooltip required' and @id='jform_email-lbl']"))).getAttribute("data-original-title");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-03
      相关资源
      最近更新 更多