modifyObjectProperty

Mate Mrse said:

Is your xpath correct? Because it looks pretty fragile…

You can check if it is correct in dev tools: enter $x(‘id(":48")/span[@class=“bA4”]/span[@class=“zF”][count(. | //[@name = ‘CPC410437’]) = count(//[@name = ‘CPC410437’])]’) and see if it is there. Somehow, I doubt it.

Besides, in your screenshot above, you have ‘//*[@name=“CPC410437”]’ in your selector editor. Just select XPath as selection method and see if it works.

Question - why we need to modify test object if the one of the parameters of the test object is constant/static: name.

We don’t need to do that. But we are in the _**modifyObjectProperty **_discussion. :smiley:

===

Mate

Correct - the xpath is changing every time i spy on it or record.
I mean - it is the same link - same test object.

Hence i tried with using just a name, since name of this Test Object, always remains the same.
But it won’t recognize it based on the name or the xpath or a combination.

Hence i tried to modify the test object so i can recognize the object based on the new properties.

I understand this is perhaps a challenge, but is there some sort of workaround for situation like this.
Katalon Recorder doesn’t have this issue. Has other issues, - hence i switched to the KS.

Thank you,
Andrew

1 Like

Try posting some of your html code with your object selected. Maybe someone could help you figure out a better xpath selector.

1 Like

I was pulling my hair off last few days, finally found your solution and its working for me. Thanks a lot for your solution.

1 Like

Hi Guys,

Related to the modifyObjectProperty method:
When the method returns an object, should the new property value not be visible in debug viewer?
I have done this in so many ways and keep on getting the old values in the “selectorCollection” property of the “new” object

//Code, I have tried with def and without def
def to = WebUI.modifyObjectProperty(findTestObject(‘Admin/WF_AuditTrail/AuditLine’), ‘text’,
‘contains’, ‘Duplicate’, false)

In variables viewer on debug mode, i get the below as selectorCollection, which is exactly the old values:
{XPATH=//span[@id=‘form:tree:0:11:ot91’], CSS=null, BASIC=//span[(contains(text(), ‘2019-08-08 19:19:43 - “QC Check duplicates” forwarded to ACC_QC_CEN [Open Workitem] [ withdraw]’) or contains(., ‘2019-08-08 19:19:43 - “QC Check duplicates” forwarded to ACC_QC_CEN [Open Workitem] [ withdraw]’)) and @ref_element = ‘Object Repository/Admin/Admin_MainPage/Frame_Main’]}

1 Like

So, apparently this was my solution

TestObject auditLine = WebUI.removeObjectProperty(findTestObject(‘Admin/WF_AuditTrail/AuditLine’), ‘text’)
auditLine.addProperty(‘text’, com.kms.katalon.core.testobject.ConditionType.CONTAINS, auditLineText)

The selectorMethods still does not look correct, but this worked for me.
Upon inspection, if the property exist, somehow, in the properties property, there are duplicates if i add the property again. according to the documention, this should have been an overwrite

1 Like

I wonder if this will ever work? It’s just confusing and not doing anything.
I was hoping that they fixed it in the meantime, but it looks like it won’t or they just forgot about it?

I even tried it with nonsense values and it’s still using the object properties of the original object.

Hi @Dominik_Kreft,
Please try the above solution where I removed the property and added it with a new value
That seemed to work for me, bit of a crazy hack, but if your back is against the wall… Let me know

1 Like

Hey @moenieb.davids,
thanks for the solution, but I haven’t made my post because of that.
I made it because it’s just not working as intended. I know that there are workarounds, and I already used one over a year ago!
Sadly you can still only work with workarounds, maybe this Keyword should be removed from Katalon Studio or should I report it somewhere else?

I think it would be helpful if the source was open for contribution. I would like to contribute, think the tool and framework is something that can make a huge impact in the industry.

@kazurayam @Jonathan_Moore I have a doubt - what if we want to pass the dynamicObject created by below code to findTestObject ?
TestObject dynamicObject = new TestObject(‘dynamicObject’).addProperty(‘xpath’, com.kms.katalon.core.testobject.ConditionType.EQUALS,
new_xpath, true)

String text = WebUI.getText(findTestObject(dynamicObject))
WebUI.verifyElementText(findTestObject(dynamicObject), ‘Classroom’)

Here in this case I am getting below error :
Reason:
groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.testobject.ObjectRepository.findTestObject() is applicable for argument types: (com.kms.katalon.core.testobject.TestObject) values: [TestObject - ‘dynamicObject’]
Possible solutions: findTestObject(java.lang.String), findTestObject(java.lang.String, java.util.Map)

Any idea how we can pass dynamicObject in this case ?
Kindly Please help me out.
Thanks in advance.

Possibly you want this:

TestObject dynamicObject = new TestObject(‘dynamicObject’).addProperty(‘xpath’, com.kms.katalon.core.testobject.ConditionType.EQUALS, new_xpath, true)

String text = WebUI.getText(dynamicObject)
WebUI.verifyElementText(dynamicObject, ‘Classroom’)

@kazurayam I tried this approach but still getting error -

2020-01-22 09:44:26.261 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to get text of object ‘dynamicObject’ (Root cause: com.kms.katalon.core.exception.StepFailedException: Unable to get text of object ‘dynamicObject’
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)

Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘dynamicObject’ located by ‘By.xpath: /html/body/div[1]/div/md-content/div[3]/div/div[2]/div/div/div[3]/div/div/div[2]/div[1]/div[3]/div[2]/div/div/div[1]/div[6]/span/span[1]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1154)

This message is telling the reason:

You need to find an appropriate XPath exression which selects the node you want. Possibly you would want to learn XPath a bit more. Here is a good tutorial of XPath:

As this tutorial shows, browser’s Dev Tool supports XPath very well. You can debug XPath expressions with Google Chrome’s Dev Tool.

1 Like