Unable to getText from ag-grid table

Hi All,

I am facing difficulty in performing getText on ag-grid table.Below is the HTML code.


The xpath I’ve written for this is -
//div[@id=‘ag-grid-table-wrapper’]/div[@class=‘customTable flex’]/div/div/div[2]/div/div[3]/div[2]/div/div/div[@row-index=‘0’]/div[contains(@class,‘dailyBudget’)]

Xpath is validated to be correct in Chrome Dev Tools, But Katalon throws error “Unable to find element with this xpath”.

2020-03-04 16:23:50.645 DEBUG .Test02_Filters_AllCasesInOne_Metrics_LR - 15: daily_budget = getText(findTestObject(“Intentwise/SP And SB Campaigns/Test02_Filters_AllCasesInOne_Metrics_LR/div_dailyBudget”))
2020-03-04 16:24:37.212 INFO c.k.k.c.webui.common.WebUiCommonHelper - Unable to find the element located by ‘By.xpath: //div[@id=‘ag-grid-table-wrapper’]/div[@class=‘customTable flex’]/div/div/div[2]/div/div[3]/div[2]/div/div/div[@row-index=‘0’]/div[contains(@class,‘dailyBudget’)]’. Please recheck the objects properties to make sure the desired element is located.
2020-03-04 16:24:37.627 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to get text of object ‘Object Repository/Intentwise/SP And SB Campaigns/Test02_Filters_AllCasesInOne_Metrics_LR/div_dailyBudget’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to get text of object ‘Object Repository/Intentwise/SP And SB Campaigns/Test02_Filters_AllCasesInOne_Metrics_LR/div_dailyBudget’
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:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(WebUiBuiltInKeywords.groovy:888)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$getText$6.call(Unknown Source)
at Test02_Filters_AllCasesInOne_Metrics_LR.run(Test02_Filters_AllCasesInOne_Metrics_LR:49)
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 TempTestCase1583319051994.run(TempTestCase1583319051994.groovy:23)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Intentwise/SP And SB Campaigns/Test02_Filters_AllCasesInOne_Metrics_LR/div_dailyBudget’ located by ‘By.xpath: //div[@id=‘ag-grid-table-wrapper’]/div[@class=‘customTable flex’]/div/div/div[2]/div/div[3]/div[2]/div/div/div[@row-index=‘0’]/div[contains(@class,‘dailyBudget’)]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1154)

Kindly please help me with this issue.
Thanks in advance.

Hey yashaswini,

If I see it correctly, you want the text $600.00 ?

Why don’t you try setting attributes instead of xpaths?

Define your Object with the attributes
comp-id equals 10463
col-id equals dailyBudget

And then try it again.

Hi @paulo.resende Thanks for responding.
comp-id keeps on changing for each session so I cannot use it. And I have tried with col-id but still I get the same error. If I scroll the table manually till the column only then Katalon can getText from it, otherwise it throws the error “Unable to find element” .

Hi
is the page using lazy loading?
if so, the element may not actually exist until it is in view - eg when you have scrolled to it.
If it isn’t visible, you can try:


if it is present on the page, you could try:

Cheers,
Dan

Based on the HTML screenshot you provided, the following CSS selector will target the highlighted gridcell:

div.ag-root .ag-body-container div[role=row] div[role=gridcell][col-id=dailyBudget]

This Groovy/JavaScript will retrieve the text inside the cell:

String js = '''
  var css = "div.ag-root .ag-body-container div[role=row] div[role=gridcell][col-id=dailyBudget]";
  return document.QuerySelector(css).innerText;
'''
String budget = WebUI.executeJavaScript(js, null)
println "Budget: " + budget

If there are more grids/tables on the page, then that css might need more tweaking.

Hi @Dan_Bown,
The table is ag-grid and the DOM elements are loaded only when it is scrolled.
I used Scroll to element but Katalon gives the same error “Unable to find object” , may be the object is not visible on DOM until it is scrolled as it is ag-grid. So I tried passing some other object which comes halfway, to Scroll to element keyword just to check the scroll action, but the scroll action is not happening, it executes without error but I cannot see the page scrolled right in the table.
Scroll to position - I couldn’t figure out the x and y co-ordinates so I couldn’t try this.

This is the ag-grid table, with the scroll bar

I need the text of the highlighted column. The scroll bar should be moved till here to come untill this column.

Did you try my method?

Sorry @Russ_Thomas , I did not understand how to implement your solution as I don’t know javascript.

Much like you didn’t need to understand DNA when you were conceived, you accepted it from your parents and use it everyday.

I gave you the JavaScript, all you have to do is use it.

One day the clever people (brain surgeons and rocket scientists, probably) will invent a search engine. Then you’ll be able to type in “Please teach me JavaScript” and find a list of websites willing to teach you for free. Until then, I guess you have to suffer not knowing the language of the internet (and your fridge, your TV and your phone and your…)

Seriously. Get a grip. Learn this stuff and take control.

Sorry @Russ_Thomas
I did try to implement this, but as I am not clear about the code and even katalon is not showing me error description, I did not know how to proceed with you. Sorry for my ignorance.

I am facing similar issue as in this post Scroll To Position does not load hidden elements , but for the horizontal scroll of ag-grid table.
So, until I scroll to the element required I cannot getText as it is ag-grid table with lazy loading(in ag-grid table not all of the rows are in the DOM until you scroll to their position).
Should we use the work around in this post or is there a solution in katalon for this ?

There’s no need to apologize, least not to me. Promise yourself you’ll own your ignorance and beat it! :slight_smile:

Once you’ve followed the advice you received on Stack Overflow then you should try my code.

However, when you try my code, be sure to type it out correctly. DON’T change the quotes - they’re not typos!

''' three single quotes '''

The three quote string is a special construct that allows you to define a multi-line string.

'''
code
more code
even more code
'''

Sure. Thanks.

Getting the below error :
2020-03-06 11:52:06.397 DEBUG .Test02_Filters_AllCasesInOne_Metrics_LR - 17: js = "
var css = “div.ag-root .ag-body-container div[role=row] div[role=gridcell][col-id=dailyBudget]”;
return documentQuerySelector(css).innerText;
"
2020-03-06 11:52:06.398 DEBUG .Test02_Filters_AllCasesInOne_Metrics_LR - 18: budget = executeJavaScript(js, null)
2020-03-06 11:52:08.374 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to execute JavaScript. (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to execute JavaScript.
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.ExecuteJavaScriptKeyword.executeJavascript(ExecuteJavascriptKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.ExecuteJavaScriptKeyword.execute(ExecuteJavascriptKeyword.groovy:37)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.executeJavaScript(WebUiBuiltInKeywords.groovy:3787)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$executeJavaScript$7.call(Unknown Source)
at Test02_Filters_AllCasesInOne_Metrics_LR.run(Test02_Filters_AllCasesInOne_Metrics_LR:65)
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 TempTestCase1583475642396.run(TempTestCase1583475642396.groovy:23)
Caused by: org.openqa.selenium.JavascriptException: javascript error: documentQuerySelector is not defined
(Session info: chrome=80.0.3987.132)

My bad - that one IS a typo

document.querySelector( ...