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"> *</span>
</label>
答案 0 :(得分:1)
尝试使用innerText
String text=driver.findElement(By.xpath("//your locator")).getAttribute("innerText");
答案 1 :(得分:0)
很遗憾,您提供的信息不足。您可以使用By.TagName("Strong)
并使用By.TagName("br")
对其进行过滤。根据您的DOM,您可以通过仅搜索特定的<div>
来改善这一点。
答案 2 :(得分:0)
要提取 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");