1

I am trying to get the text/content on the tooltip/help text. I am using selenium java.

Expected Result: To get the text so that I can verify by assertEquals

Actual Result: Not getting the text. It is getting null values. No error as such

HTML CODE:

<lightning-primitive-bubble class="slds-popover slds-popover_tooltip slds-nubbin_bottom-left slds-fall-into-ground" role="tooltip" id="salesforce-lightning-tooltip-bubble_8869b6bc-5567-f877-4ce1-037d1eaa3c37" style="position: fixed; min-width: 75px; z-index: 9104; left: 421px; right: auto; top: 114px;" data-position-id="lgcp-1000014"><div class="slds-popover__body">When did the current support plan begin?</div></lightning-primitive-bubble>

Mouse hover is done successfully. Only the text of the help text is not retrieved in the output Here is my code

String help = driver.findElement(By.xpath("(//lightning-primitive-bubble/div)[1]")).getText();
System.out.printf("Help text >", help);

I have tried multiple things like I have tried full xpath, absolute xpath, css selector, etc. Also tried multiple methods .getText(); .getAttribute("innerText"), .getAttribute("textContent"),etc.

Referred following link Unable to extract the text using gettext in Selenium WebDriver and also unable to click it

https://www.seleniumeasy.com/selenium-tutorials/how-to-verify-tooltip-text-with-selenium-webdriver-using-java

Can someone please help me to get the text

  • Did you try hovering over the element with ActionChains? Selenium documentatiion can be found at https://www.selenium.dev/documentation/ – Barry the Platipus Aug 09 '22 at 14:48
  • Yes, I did hovering by using Action class and driver.moveToElement(hoverElement).perform(); method. Just struggling to get the text out of it. – Mansi Palav Aug 10 '22 at 12:27

1 Answers1

0

I got a solution for this and got to learn new things

So the web element attribute values is dynamic it keeps on changing its value before hover, on hover, after hover. hence, I was not able to trace the text residing in it. So first thing I would suggest is to analyze the attribute values and take the one which is needed.

Code before hover:

<lightning-primitive-bubble class="slds-hide slds-popover slds-popover_tooltip slds-fall-into-ground slds-nubbin_bottom-left" style="position: absolute; min-width: 75px;" role="tooltip" id="salesforce-lightning-tooltip-bubble_e3b7781a-384d-c9bf-0b46-4d6fa6b1bba4"><div class="slds-popover__body"></div></lightning-primitive-bubble>
<div class="slds-popover__body"></div>
</lightning-primitive-bubble>

On Hover: class and id both got change for example class = "slds-popover slds-popover_tooltip slds-nubbin_bottom-left slds-rise-from-ground"

After hover:

<lightning-primitive-bubble class="slds-popover slds-popover_tooltip slds-nubbin_top-left slds-fall-into-ground slds-hide" style="position: fixed; min-width: 75px; z-index: 9100; left: 421px; right: auto; top: 100px;" role="tooltip" id="salesforce-lightning-tooltip-bubble_aaddfd6a-2e8f-0462-d8f5-4574cd12e11f"
  data-position-id="lgcp-1000002">
  <div class="slds-popover__body">When did the current support plan begin?</div>
</lightning-primitive-bubble>

So in my case the tooltip text was coming on mouse hover and after mouse hover as well. So I took the dynamic element which is on mouse hover

//Hover on help text
we = driver.findElement(By.xpath("(//lightning-helptext)[3]"));
         actions.moveToElement(we).build().perform();

//Found the dynamic web element on mouse hover     
String actualHelpText = new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class=\"slds-popover slds-popover_tooltip slds-nubbin_bottom-left slds-rise-from-ground\"]"))).getText();
System.out.println(new WebDriverWait(driver, Duration.ofSeconds(10)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@class=\"slds-popover slds-popover_tooltip slds-nubbin_bottom-left slds-rise-from-ground\"]"))).getText());
assertEquals(actualHelpText,"When did the current support plan begin?");

Please hit the vote to the answer if you got help with this.

  • If you would have searched there are more then 10 solutions related to _Mouse Hover_ discussions on SO. Furhter your question lacks basic information e.g. the HTML of the element containing the help text. Hence your question was unanswerable. However the codeblock can still be optimized. – undetected Selenium Aug 11 '22 at 12:59
  • Ya I got more than 10 solutions but dint found suitable for my problem and I was not knowing that the HTML element was changing as per my actions at the start. hence placed only one html. Anyways, Thank you for your time and help.:) – Mansi Palav Aug 12 '22 at 04:53