Unable to get text from object

Hi Katalon Experts,

I have the object with the below properties from where I want to get the text

when I run the test, it says that the text is ’ ’

also I tried using get attribute and it says is null

Any suggestion?

Thanks,
Ruben B

1 Like

Hi Ruben,

Perhaps you can try using this:

String objectText = WebUI.getText(findTestObject("Page_Holiday Company Calendar Insider/select_2019"))
println objectText

And use attribute “id” instead of “class”. Detect object by ‘id’

Hope that helps. . . :slight_smile:

1 Like

Hi Arnel,

Thanks for your help. Unfortunately, it didn’t work :slightly_frowning_face:

08-23-2019 10:47:08 AM objectText = getText(findTestObject(“Page_Holiday Company Calendar Insider/select_2019”))

Elapsed time: 0.448s

Unable to get text of object (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to get text of object

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.getText(GetTextKeyword.groovy:88)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.execute(GetTextKeyword.groovy:67)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(WebUiBuiltInKeywords.groovy:888)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getText$7.call(Unknown Source)

at Holidays.run(Holidays:40)

at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)

at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)

at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:337)

at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)

at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)

at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)

at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)

at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)

at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)

at TempTestCase1566575204530.run(TempTestCase1566575204530.groovy:21)

Caused by: java.lang.IllegalArgumentException: Object is null

at com.kms.katalon.core.helper.KeywordHelper.checkTestObjectParameter(KeywordHelper.java:33)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword$_getText_closure1.doCall(GetTextKeyword.groovy:76)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword$_getText_closure1.call(GetTextKeyword.groovy)

at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.getText(GetTextKeyword.groovy:88)

at com.kms.katalon.core.webui.keyword.builtin.GetTextKeyword.execute(GetTextKeyword.groovy:67)

at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:56)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(WebUiBuiltInKeywords.groovy:888)

at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getText$7.call(Unknown Source)

at Script1566423044543.run(Script1566423044543.groovy:40)

… 11 more

)

Thanks,
Ruben B

Hi,
Share the HTML of the object

Hi @HeleneB,

Here you go

Thanks,
Ruben B

The very first line in your error log looks incorrect. When you get an object error null like this its because the object in your script is null… NOT that the object isn’t present in the UI. That would be a different error.

objectText = getText(findTestObject(“Page_Holiday Company Calendar Insider/select_2019”))

getText() can’t be called on it’s own like this. WebUI.getText() is the correct way. Copy exactly what @Arnel posted in his comment.

String objectText = WebUI.getText(findTestObject(“Page_Holiday Company Calendar Insider/select_2019”))
println objectText

Thanks for the info @Eric_Montou, unfrotunately it didn’t get the text

image

Thanks,
Ruben B

Hi @jpereyra

Can you share the script you’re currently using, the devil is usually in the details.

Also, the forum editor has an option for you to wrap around the lines of code so that they stand out differently, it’d be very helpful for us to easily see what’s going on.

This is actually good news because now you solved the first issue! :grin: Now we have to solve this second issue!

It looks like its finding an object now but the text is empty. Usually this means you are looking at the wrong object or an object you weren’t expecting to. I would look at the properties on your object again. The verify first picture you posted it looks like the “class” property is the only one you are using to detect the object. There are probably multiple elements on the page that have the same value for that same class. So you need to pick a more unique property or use a combination of all of them.

I would use the id and tag properties.

The issue may be that you are getting the contents of a Select/Dropdown field. You may only be looking at the first item. I have done something similar with:

String allItems = WebUI.getText(findTestObject('Object/select-Dropdown'))
List items=allItems.split("\\r?\\n")
itemName=items[0]

It looks like you have the right object, but there could be more items depending on how the items are listed in the select object.

String js = '''
  var sel = document.querySelector("#edit-year");
  return sel.options[sel.selectedIndex].innerText;
  // can also try:
  // return sel.options[sel.selectedIndex].text;
  // return sel.options[sel.selectedIndex].value;
'''
String text = WebUI.executeJavaScript(js, null)

Hi Peter,

Thanks for the information, it didn’t work



image

Please let me know if I’m missing anything, i’m pretty new using Katalon.

Thanks,
Ruben B

Hi @Eric_Montou,

PFB the object properties

I have tried using all of them (one by one) and the object can be located only using class otherwise it can’t be located.

Thanks,
Ruben B

Hi @ThanhTo,

PFB below the script

import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys

WebUI.openBrowser(’’)

WebUI.navigateToUrl(‘https://company.site.com/saml_login?ReturnTo=https%3A//insider.illumina.com/’)

WebUI.setText(findTestObject(‘Page_company - Sign In/input_Username_username’), ‘jpereyra’)

WebUI.setEncryptedText(findTestObject(‘Page_company - Sign In/input_Password_password’), ‘IxeH2LO7Fyi3mwGtluhdRg==’)

WebUI.click(findTestObject(‘Page_company - Sign In/input_Remember me_okta-signin-submit’))

WebUI.scrollToElement(findTestObject(‘Page_Home page Insider/div_Holidays Section Home Page’), 0)

WebUI.verifyElementPresent(findTestObject(‘Object Repository/Page_Home page Insider/div_Holidays Section Home Page’), 0)

WebUI.verifyElementVisible(findTestObject(‘Page_Home page Insider/div_Holidays Section Home Page’))

WebUI.click(findTestObject(‘Object Repository/Page_Home page Insider/span_Holidays’))

WebUI.verifyElementPresent(findTestObject(‘Object Repository/Page_Holiday Company Calendar Insider/div_Holidays Section Holidays page’),
0)

WebUI.verifyElementVisible(findTestObject(‘Page_Holiday Company Calendar Insider/div_Holidays Section Holidays page’))

String objectText = WebUI.getText(findTestObject(‘Page_Holiday Company Calendar Insider/select_2019’))
println objectText

WebUI.verifyElementPresent(findTestObject(‘Object Repository/Page_Holiday Company Calendar Insider/div_Next Holidays’),
0)

WebUI.verifyElementVisible(findTestObject(‘Page_Holiday Company Calendar Insider/div_Next Holidays’))

WebUI.closeBrowser()

Thanks,
Ruben B

It shows there is nothing in [0]. With that in mind, what is the .size() of that list and do any of the other elements contain a value?

Ok after reviewing the html you posted here:

Your object is pointing to the select element using class=“form-select”

From this point in the tree, the object has no text in the element. And when I look at your original post I realize that you tried getting the text of the attribute. But there is no text there either which is exactly what your error message is saying.

It looks like what you need to do is instead of using getText() use

getAttribute(findTestObject(“path_to_your_object”), ‘value’)

Instead of the select element you will have to point to the option element and get the attribute of the value on THAT. NOT the object you are currently pointing to.

The text is inside the <option> element. WebUI Get Text says:

It’s essentially innerText with trim().

Targeting a selector for any suitable ancestor should work. Otherwise, it’s a bug (doubtful).

The only text I see is “Year” on the parent element label tag. The option element doesn’t have text. It has a value that IS hidden by CSS.

It does…

image

He hasn’t shared any CSS - or did I miss something? That screenshot contains no evidence of CSS hiding the text “2019”.

WOW my apologies for being a blind bat. The text is there and not hidden by CSS

The point I was trying to make here was that the text is present in the CSS. The value attribute is the same as the text. So if it were me I would just get the value of the “value” attribute and avoid getting text from anywhere.

I’ve had issues in the past using get Text so I try to avoid it if I can.