priya
priya

Reputation: 1

How to find tooltip text message that is <Strong><br> tag in java

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

Its giving me null value.

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>

Upvotes: 0

Views: 88

Answers (3)

undetected Selenium
undetected Selenium

Reputation: 193258

To extract the tooltip text message you need to induce WebDriverWait for the desired element to be visible and you can use the following solution:

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

Upvotes: 0

murali selenium
murali selenium

Reputation: 3927

Try with innerText

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

Upvotes: 1

elp
elp

Reputation: 870

Unfortunately this is not that much information you provided. You could use By.TagName("Strong) and filter them using By.TagName("br"). Depending on your DOM you can improve this a lot by just searching in specific <div> for instance.

Upvotes: 0

Related Questions