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?
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.
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
Can you share us your test object (xpath specifically) to evaluate, and remember to censor or change your sensitive data in the image.
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.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:
WebElement element = WebUiCommonHelper.findWebElement(ObjectRepository.findTestObject("path/to/my/object"), 30);
String text = element.getAttribute("textContent");
Hope this helps!
I did it your way and success.
can anyone help me like what we have to pass at place of 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.