[Web UI] Can’t get text from pop-up

I wanted to check the content of pop-ups by using “Get Text” method but ran into troubles.

Here is how I’ve done it:

Pic 1: My script:

Pic 2: Result (I got the return but it’s always a null value)

Do you have any ideas about what went wrong with my script? And if the “Get Text” method couldn’t work, what else could?

Thanks!

Get Text returns a VISIBLE text of the interacting element. In your case, the text is encapsulated as an attribute of the element, e.g:

  • <div class="container posts">Some text here</div> -> Some text here is a VISIBLE TEXT
  • <div class="container posts" value="Some text here"></div> -> Some text here is now an attribute of a element

In this case, please use Get Element Attribute keyword instead and pass in an attribute name you want to get.

1 Like

Thank you!
I tried to use the Get Attribute method, but the result is still “Null”

@doanthithuy Can you provide the HTML of the element you are trying to get the text from? Even better, can you provide the HTML of the popup as a whole (just to be sure it isn’t sitting within another frame or something). Thanks.

You can see my HTML of the elements here
https://pastebin.com/dpMPg59b

Thanks

Hi @doanthithuy,
Can you share us your test object (xpath specifically) to evaluate, and remember to censor or change your sensitive data in the image.

Thanks

I’m assuming you’re trying to get the text of the following element from your HTML snippet:

Try doing the following:

1.) I’m not sure how you’ve configured your Test Object for this element, but here’s a brute-force example of how you could do it using XPath:

2.) Try getting the “textContent” attribute value for the element:

import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

String text = WebUI.getAttribute(ObjectRepository.findTestObject("path/to/my/object"), "textContent");

3.) Backup plan: you can always do this using Selenium itself:

import org.openqa.selenium.WebElement
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.webui.common.WebUiCommonHelper

WebElement element = WebUiCommonHelper.findWebElement(ObjectRepository.findTestObject("path/to/my/object"), 30);
String text = element.getAttribute("textContent");

Hope this helps!

3 Likes

I did it your way and success.
Thanks

can anyone help me like what we have to pass at place of textContent
WebUI.getAttribute(ObjectRepository.findTestObject(“path/to/my/object”), “textContent”);

You don’t replace “textContent” with anything. This is the name of an actual attribute of the HTML element that we are trying to retrieve.