modifyObjectProperty

Hi
I want to modify a property at run time. I perform the steps that are indicated in the docs:
'Modify xpath of \'Login\' button'
new_btn = WebUI.modifyObjectProperty(findTestObject('Page_Login/btn_Login'), 'xpath', 'equals', '//*[@type=\"button\"]', false)
'Click on new_btn'
WebUI.click(findTestObject('new_btn'))
the Property changes correctly
But in the step: WebUI.click(findTestObject('new_btn')) fail
[INFO] - Finding Test object with id 'Object Repository/new_btn' [WARNING] - Test object with id 'Object Repository/new_btn' does not exist [INFO] - Finding Test object with id 'Object Repository/' [WARNING] - Test object with id 'Object Repository/' does not exist [INFO] - Checking object [FAILED] - Unable to click on object (Root cause: java.lang.IllegalArgumentException: Object is null)
1 Like

Is not need to use findTestObject when you use your created test object as test object parameter in built-in keyword. You only need to pass in the parameter without using findTestObject.

Please modify the doc at https://docs.katalon.com/display/KD/[WebUI]+Modify+Object+Property
the example is wrong because it uses findTestObject

Thanks for the answers

If I do the following:
new_btn = WebUI.modifyObjectProperty(findTestObject(``'Page_Login/btn_Login'``),``'xpath'``, 'equals'``, '//*[@type=\"button\"]'``, true)

WebUI.click(findTestObject(``new_btn``)) // without quotes

Returns signature error, because findTestObject expects a string

If I do the following:
String new_btn = WebUI.modifyObjectProperty(findTestObject(``'Page_Login/btn_Login'``),``'xpath'``, 'equals'``,``'//*[@type=\"button\"]'``, true)

WebUI.click(findTestObject(``new_btn``))

return the same:

[INFO] – Finding Test object with id ‘Object Repository/new_btn’
[WARNING] – Test object with id ‘Object Repository/new_btn’ does not exist
[INFO] – Finding Test object with id ‘Object Repository/’
[WARNING] – Test object with id ‘Object Repository/’ does not exist
[INFO] – Checking object
[FAILED] – Unable to click on object (Root cause: java.lang.IllegalArgumentException: Object is null)

Thanks for the answers

If I do the following:
new_btn = WebUI.modifyObjectProperty(findTestObject(``'Page_Login/btn_Login'``),``'xpath'``, 'equals'``, '//*[@type=\"button\"]'``, true)

WebUI.click(findTestObject(``new_btn``)) // without quotes

Returns signature error, because findTestObject expects a string

If I do the following:
String new_btn = WebUI.modifyObjectProperty(findTestObject(``'Page_Login/btn_Login'``),``'xpath'``, 'equals'``, '//*[@type=\"button\"]'``, true)

WebUI.click(findTestObject(``new_btn``))

return the same:

[INFO] – Finding Test object with id ‘Object Repository/new_btn’
[WARNING] – Test object with id ‘Object Repository/new_btn’ does not exist
[INFO] – Finding Test object with id ‘Object Repository/’
[WARNING] – Test object with id ‘Object Repository/’ does not exist
[INFO] – Checking object
[FAILED] – Unable to click on object (Root cause: java.lang.IllegalArgumentException: Object is null)

It should be

WebUI.click(new_btn)

Hi there,

This line should be corrected:

WebUI.click(findTestObject(``'new_btn'``))

To:

WebUI.click(findTestObject(``new_btn``))

The root cause is ‘new_btn’ will be acted as string if you put it between single quotes . You need to call variable, that’s why you shouldn’t put it between single quotes

@“Carlos Fontana”, can confirm this.
calling the modified object should not contain findTestObject and object name should not be in quotation marks.

apart from this, i ran into some problems when leaving the command without timeout.

setting it up like this, worked like a charm for me:

WebUI.verifyElementPresent(new_btn, 10)

Ops very sorry guys. I’ve corrected that Javadoc :). Once again sorry for this and thanks for pointing out that error.

Regards

Hi, The docs at https://docs.katalon.com/display/KD/[WebUI]+Modify+Object+Property
still say eg:

new_btn = WebUI.modifyObjectProperty(findTestObject('Page_Login/btn_Login'), 'xpath', 'equals', '//*[@type=\"button\"]', false)

however it seems this first finds the object without modifying the xpath, and the comment above says "calling the modified object should not contain findTestObject " - so what would be the correct code?

--------------------
on further testing, I got a working code like:

TestObject dynamicObject = new TestObject('dynamicObject').addProperty('xpath', com.kms.katalon.core.testobject.ConditionType.EQUALS, newXPath, true)
WebUI.waitForElementVisible(dynamicObject, 3)

creating a new object rather than getting a TestObject from the repository and modifying it.

I didn’t find this type of usage in the documentation, just guesswork and hints on the forums, so it would be good to have some clarification about which is the recommended syntax.

3 Likes

Jonathan Moore said:

Hi, The docs at https://docs.katalon.com/display/KD/[WebUI]+Modify+Object+Property
still say eg:

new_btn = WebUI.modifyObjectProperty(findTestObject('Page_Login/btn_Login'), 'xpath', 'equals', '//*[@type=\"button\"]', false)

however it seems this first finds the object without modifying the xpath, and the comment above says "calling the modified object should not contain findTestObject " - so what would be the correct code?

--------------------
on further testing, I got a working code like:

TestObject dynamicObject = new TestObject('dynamicObject').addProperty('xpath', com.kms.katalon.core.testobject.ConditionType.EQUALS, newXPath, true)

WebUI.waitForElementVisible(dynamicObject, 3)


  

creating a new object rather than getting a TestObject from the repository and modifying it.

I didn't find this type of usage in the documentation, just guesswork and hints on the forums, so it would be good to have some clarification about which is the recommended syntax.

  

  

  

This solution worked better for me, so thank you for posting this. The Modify Object Property didn’t work at all even after following the example in the docs.

This is what I had when using modifyObjectProperty where orgName is actually a variable:

newLabel = WebUI.modifyObjectProperty(findTestObject(object path), 'text'``, 'contains'``, orgName``, false)

WebUI.click(newLabel)

Jonathan Moore said:

Hi, The docs at https://docs.katalon.com/display/KD/[WebUI]+Modify+Object+Property
still say eg:

new_btn = WebUI.modifyObjectProperty(findTestObject('Page_Login/btn_Login'), 'xpath', 'equals', '//*[@type=\"button\"]', false)

however it seems this first finds the object without modifying the xpath, and the comment above says "calling the modified object should not contain findTestObject " - so what would be the correct code?

--------------------
on further testing, I got a working code like:

TestObject dynamicObject = new TestObject('dynamicObject').addProperty('xpath', com.kms.katalon.core.testobject.ConditionType.EQUALS, newXPath, true)

WebUI.waitForElementVisible(dynamicObject, 3)


  

creating a new object rather than getting a TestObject from the repository and modifying it.

I didn't find this type of usage in the documentation, just guesswork and hints on the forums, so it would be good to have some clarification about which is the recommended syntax.

  

This works like a charm, thanks!!
ModifyObjectProperty isn’t working at all, wonder if it’s buggy or what exactly the issue is.

Hi

I face a very same error. I am very new to Katalon Studio.

Here is the 2 lines that error for me:

WebUI.waitForElementPresent(findTestObject(‘html_Bronto - Editing Message’), 10)

WebUI.click(findTestObject(‘html_Bronto - Editing Message’))

However i am not sure the object property gets modified during the run. Maybe I am mistaken?

Here are the screen shots of the error and properties.

Perhaps it is a different issue? Please advise.

**Note: **I found that the actual click was not really an important step (or action) - so for now I have commented the 2 lines and it seems to work.
Still would like to know based on the above screen shots if the object does gets modified.

Thank you,
Andrew

Error.png

Object.png

Are you actually using an existing object you are trying to modify?

Because, your log says “The object with id 'Object Repository/” does not exist.

Hi Mate

Actually i am not trying to modify anything. It is an existing object.
How do I know it is changing “on the fly”? And if yes - how to make sure it always recognized - by wildcarding?

Thank you very much!
Andre

Now I noticed that the Selector Editor shows your html_Bronto element isn’t defined properly, there are some brackets missing.

If you are changing a property, you could check the new value using WebUI.getAttribute() or WebUI.getCSSValue().

Mate Mrse said:

Now I noticed that the Selector Editor shows your html_Bronto element isn’t defined properly, there are some brackets missing.

If you are changing a property, you could check the new value using WebUI.getAttribute() or WebUI.getCSSValue().

Hi Mate

Thank you! I will try to utilize this suggestion.

Is there anything else that needs to be done? I am asking since i am just learning using **script **function of Katalon Studio. Mostly did manual or recording.

If there is a good example - please share.

Thank you & Have a Great Day!
Andrew

Mate Mrse said:

Now I noticed that the Selector Editor shows your html_Bronto element isn’t defined properly, there are some brackets missing.

If you are changing a property, you could check the new value using WebUI.getAttribute() or WebUI.getCSSValue().

Hi Mate

Thank you again for your advice earlier. It has taken me some time, but i now have tried both options recommended above.

Sorry for the long post.

I found a good example to demonstrate. It is a “From” link in the inbox. In this specific case - the “xpath” is being changed every time user clicks on the object. However the “name” property always stays the same.

Modifying test object:

new_email = WebUI.modifyObjectProperty(findTestObject(‘Page_Gmail/span_CPC410437’), ‘name’, ‘equals’, ‘CPC410437’, false)

WebUI.waitForElementVisible(new_email, 15)

WebUI.click(new_email)

Error:
_Unable to click on object ‘Object Repository/Page_Gmail/span_CPC410437’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Gmail/span_CPC410437’ located by 'By.xpath: ’ not found)
_
Note: At this point the test object property does get modified.

Adding a new test object:

TestObject dynamicObject = new TestObject(‘Page_Gmail/dynamicObject’).addProperty(‘name’, com.kms.katalon.core.testobject.ConditionType.EQUALS, ‘span_CPC410437’, false)

WebUI.waitForElementVisible(dynamicObject, 5)

WebUI.click(dynamicObject)

Error:
Unable to click on object ‘Page_Gmail/dynamicObject’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Page_Gmail/dynamicObject’ located by 'By.xpath: ’ not found)

Here is the properties of this object:

Thank you
Andrew

Inbox_From_Link.png

Inbox_From_Link_property.png

Hi, Andrew

Set the last parameter of the ModifyObjectProperty to ‘true’.
That should do the trick.

Mate Mrse said:

Hi, Andrew

Set the last parameter of the ModifyObjectProperty to ‘true’.
That should do the trick.

Hi Mate

I have tried with true for ModifyObjectProperty. I tried to modify based on the xpath and the name.
In both cases i get an error - please see below.

Modify TO by xpath:

Unable to click on object ‘Object Repository/Page_Gmail/span_CPC410437’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException:

Web element with id: ‘Object Repository/Page_Gmail/span_CPC410437’ located by 'By.xpath:

id(":48")/span[@class=“bA4”]/span[@class=“zF”][count(. | //[@name = ‘CPC410437’]) = count(//[@name = ‘CPC410437’])]’ not found)

Modify TO by name:

Unable to wait for object ‘Object Repository/Page_Gmail/span_CPC410437’ to be visible (Root cause: org.openqa.selenium.StaleElementReferenceException:

stale element reference: element is not attached to the page document

Please advise if you spot what is incorrect.

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

**

Thank you very much.
Andrew

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:

===