Using waitForElementPresent without an Object

Hi @Russ Thomas,

I’m new to Automation and Katalon Studio. I want to try and use what you talk about above about not using the OR, but not quite sure how to start. Can you provide a more complete example, maybe post a sample Katalon project on Github.

Thanks,
Jon

Hi Jon

Perhaps, maybe, one day :wink:

I seriously don’t have the time right now and can’t see far enough ahead to say when that might change.

Sorry.

No worries, I appreciate the quick response.

Thank you, Russ, but it seems my code still isn’t working. Here’s the relevant part:

WebUI.modifyObjectProperty(findTestObject("DUMMY"), 'css', 'equals', 'input[placeholder="Base"]', true)
WebUI.doubleClick(findTestObject("DUMMY"))
CustomKeywords.'metode.webElementi.popuniComboBox'(findTestObject("DUMMY"), findTestData("R-TABLE(1)").getValue(1, 10), 5)

The log says the ‘dummy’ object has been found and the property has been successfully modified:

04-04-2018 09:05:02 AM - [START]  - Start action : modifyObjectProperty
04-04-2018 09:05:02 AM - [INFO]   - Finding Test Object with id 'Object Repository/DUMMY'
04-04-2018 09:05:02 AM - [INFO]   - Check Test Object
04-04-2018 09:05:02 AM - [INFO]   - Check property name
04-04-2018 09:05:02 AM - [INFO]   - Check modify value
04-04-2018 09:05:02 AM - [INFO]   - Check match condition
04-04-2018 09:05:02 AM - [PASSED] - Modify property of object successfully
04-04-2018 09:05:02 AM - [END]    - End action : modifyObjectProperty

But when it continues, Katalon tries to doubleclick the original css path (before modification) and finds 6 elements (not the ones I targeted):

04-04-2018 09:05:02 AM - [START]  - Start action : doubleClick
04-04-2018 09:05:02 AM - [INFO]   - Finding Test Object with id 'Object Repository/DUMMY'
04-04-2018 09:05:02 AM - [INFO]   - Checking object
04-04-2018 09:05:02 AM - [INFO]   - Checking timeout
04-04-2018 09:05:02 AM - [INFO]   - Finding web element with id: 'Object Repository/DUMMY' located by 'By.cssSelector: div.c-header-close' in '30' second(s)
04-04-2018 09:05:02 AM - [INFO]   - Found 6 web elements with id: 'Object Repository/DUMMY' located by 'By.cssSelector: div.c-header-close' in '30' second(s)
04-04-2018 09:05:02 AM - [INFO]   - Double clicking on object: 'Object Repository/DUMMY'
04-04-2018 09:05:02 AM - [PASSED] - Object: 'Object Repository/DUMMY' is double clicked on
04-04-2018 09:05:02 AM - [END]    - End action : doubleClick

So, the test fails because the custom keyword sends text to wrong elements and I get this exception:

04-04-2018 09:05:02 AM - [START]  - Start action : metode.webElementi.popuniComboBox
04-04-2018 09:05:02 AM - [INFO]   - Finding web element with id: 'Object Repository/DUMMY' located by 'By.cssSelector: div.c-header-close' in '30' second(s)
04-04-2018 09:05:02 AM - [INFO]   - Found 6 web elements with id: 'Object Repository/DUMMY' located by 'By.cssSelector: div.c-header-close' in '30' second(s)
04-04-2018 09:05:02 AM - [INFO]   - Clearing text of object 'Object Repository/DUMMY'
04-04-2018 09:05:03 AM - [FAILED] - Unable to set text 'some text' of object 'Object Repository/DUMMY' (Root cause: org.openqa.selenium.InvalidElementStateException: invalid element state: Element must be user-editable in order to clear it.

Am I doing something wrong or is this a Katalon bug?

I’m having the same issue. Can’t seem to get this to work, no matter what I try.

Guys, it would help a lot if you showed your code (along with the errors reported in the log viewer).

So, as a guess, I’d say your code is modifying the object you retrieved from the OR, then your code uses the object from the OR.

Right?

Problem: **that is not the object you modified.

**The manual states the following:

[WebUI] Modify Object Property

This keyword does not modify the object
saved in Object Repository
, instead, it creates another test object,
modifies and returns this test object. Hence, users must use a variable
to store the returned object
.

So, in brief,

def myModifiedObject = WebUI.modifyObjectProperty(...)
WebUI.doSomething(modifiedObject)

Let me know how it goes…

Russ

1 Like

*facepalm*
You are right, that was the problem! I just stored my WebUI.modifyObjectProperty resutlt in a variable and it works perfectly. Thank you!

Great post! :o

2018/06/15
Inspired by the discussion here, I made another post “Parameterized Test Object on the fly”. See

1 Like

Hi

I tried each and every option listed here. My test object is still not being recognize.
Maybe i am repeating the same question. But obviously it did not resolve the problem.

The scenario is very simple. Click on the email arrived.

So here are various solutions suggested.

1. Created my own test object and called it Email1.

Xpath: id(“:38”)/span[@class=“bA4”]/span[@class=“yP”]’ not found)

I get this error:
Unable to click on object ‘Object Repository/Page_Inbox (479) - andrewkhomskigma/Email1’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Inbox (479) - andrewkhomskigma/Email1’ located by ‘By.xpath: id(“:38”)/span[@class=“bA4”]/span[@class=“yP”]’ not found)

Error occurs at this 2 lines:

WebUI.waitForElementPresent(findTestObject(‘Page_Inbox (479) - andrewkhomskigma/Email1’), 10)

WebUI.click(findTestObject(‘Page_Inbox (479) - andrewkhomskigma/Email1’))

2. Used test object recorded and added to Object Repository.

I get this error:
Unable to click on object ‘Object Repository/Page_Inbox (479) - andrewkhomskigma/span_AH 10062018 1137’ (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_Inbox (479) - andrewkhomskigma/span_AH 10062018 1137’ located by ‘By.xpath: id(“:38”)/span[@class=“bA4”]/span[@class=“yP”][count(. | //span[@class = ‘yP’ and @name = ‘AH 10/06/2018 11:37’ and @data-hovercard-owner-id = ‘28’ and (text() = ‘AH 10/06/2018 11:37’ or . = ‘AH 10/06/2018 11:37’)]) = count(//span[@class = ‘yP’ and @name = ‘AH 10/06/2018 11:37’ and @data-hovercard-owner-id = ‘28’ and (text() = ‘AH 10/06/2018 11:37’ or . = ‘AH 10/06/2018 11:37’)])]’ not found)

Error occurs at this 2 lines:

WebUI.waitForElementPresent(findTestObject(‘Page_Inbox (479) - andrewkhomskigma/span_AH 10062018 1137’), 10)

//WebUI.click(findTestObject(‘Page_Inbox (479) - andrewkhomskigma/span_AH 10062018 1137’))

Appreciate any advise - i am not sure what else left here or what i missed…

Thank you!
Andrew

Option1.png

Option2A.png

In both cases, findTestObject is failing to find an element to click on. You are using an xpath that clearly does not work.

Strictly speaking, debugging and fixing xpath expressions is not my forte, FWIW. And it’s a little off topic for this thread. Try reposting a new thread “What’s wrong with my XPATH?”, maybe someone with more xpath experience will chime in.

Russ Thomas said:

In both cases, findTestObject is failing to find an element to click on. You are using an xpath that clearly does not work.

Strictly speaking, debugging and fixing xpath expressions is not my forte, FWIW. And it’s a little off topic for this thread. Try reposting a new thread “What’s wrong with my XPATH?”, maybe someone with more xpath experience will chime in.

Russ

It is nothing to do with xpath. Actually it is not off topic. I am facing the same issue.

I have tried with each parameter individually or combined.
Modified an existing object captured by Spy Object.
Or have created a new Test Object from scratch - as per your recommendation i think.

I am also not clear why would i use this: def myModifiedObject = WebUI.modifyObjectProperty(…)

I know object name, or xpath or id. Why specifying it directly - it is not recognized by KS?

I am just not sure what is going on.

Thanks
Andrew

Okay, let’s try something else. Referring back to your last image…

You have a name setting checked. But the name setting has a time value. Wouldn’t that change per email?

Try this: turn off everything except the xpath.

Russ Thomas said:

Okay, let’s try something else. Referring back to your last image…

You have a name setting checked. But the name setting has a time value. Wouldn’t that change per email?

Try this: turn off everything except the xpath.

Thank you Russ!

I will try leaving just xpath. I thought i tried on my test object created manually - but will try again.

I tried something else though.

The Name Test Object is basically “from” name - that appears in the Inbox. And for my testing purposes, i make it be the same thing. Say Email1, and another email will have “from” name
will be **Email2.
**
Of course it would be nice to parametrize such objects with solutions you recommended. But this is kind of far ahead. I thought if it doesn’t work in a simple way - i did not want to even try with making modifications to the object. Besides - the NAME - always stays the same. Tag is always stays the same. And i think even the xpath stays the same all the time.

In any case - i will try with **xpath **only and will report back.

Thank you so much for your guidance!
Andrew

Russ Thomas said:

Okay, let’s try something else. Referring back to your last image…

You have a name setting checked. But the name setting has a time value. Wouldn’t that change per email?

Try this: turn off everything except the xpath.

Good Evening Russ

I have tried and still my object is not being recognized.
Here are some more details. Maybe i am blind and do not see something obvious?

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

Maybe i am blind and do not see something obvious?

Then that makes two of us :frowning: And as a reminder, read my first response to you again - xpath is not my thing!

That said…

Can you paste some of the HTML surrounding the span(s) in question? I’m now concerned you are trying to click on the wrong element entirely (spans do not have a name attributes: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes). If some JavaScript is adding a name property, then there is much more going on with that page than meets the eye.

Note: in HTML, property and attribute are different things. In Katalon they may or may not reflect the same things and they may or may not be consistent with each other (one reason why I steer clear of TestObjects and xpaths).

Paste a copy of the HTML and make a list of things that STAY THE SAME before and after a click.

Russ Thomas said:

Maybe i am blind and do not see something obvious?

Then that makes two of us :frowning: And as a reminder, read my first response to you again - xpath is not my thing!

That said…

Can you paste some of the HTML surrounding the span(s) in question? I’m now concerned you are trying to click on the wrong element entirely (spans do not have a name attributes: https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes). If some JavaScript is adding a name property, then there is much more going on with that page than meets the eye.

Note: in HTML, property and attribute are different things. In Katalon they may or may not reflect the same things and they may or may not be consistent with each other (one reason why I steer clear of TestObjects and xpaths).

Paste a copy of the HTML and make a list of things that STAY THE SAME before and after a click.

Good Evening Russ

This time i did some more research on my own. Hence did not want to bother you or anyone else.

Here is the html behind the object. I have highlighted attributes that stay same in Bold.

BEFORE CLICK:

<span class=“bqe” data-thread-id="#thread-f:1603299835216060460"
data-legacy-thread-id=“164010b49a7ee02c”
data-legacy-last-message-id=“164010b49a7ee02c”>CPL413000

<span
class=“zF” email="finmc@e.finmc.com"
name=“CPL413000” data-hovercard-id="finmc@e.finmc.com" data-hovercard-owner-id=“26”>CPL413000

AFTER CLICK:

<span data-thread-id="#thread-f:1603299835216060460"
data-legacy-thread-id=“164010b49a7ee02c”
data-legacy-last-message-id=“164010b49a7ee02c”>CPL413000

<span class=“yP” email="finmc@e.finmc.com"
name=“CPL413000” data-hovercard-id="finmc@e.finmc.com"
data-hovercard-owner-id=“26”>CPL413000

Note:

- Once you mentioned before and after click - i started looking into this and i think i made it work.

I mean it runs for me in this code below:

WebUI.waitForElementPresent(findTestObject(‘Page_Inbox/span_CPL413000’), 15)
WebUI.click(findTestObject(‘Page_Inbox/span_CPL413000’))

However only if this TO has the following enabled:

tag = "span"

class = "zF"

name= "CPL413000"

text = "CPL413000"

xpath = “id(”:2w")/span[@class=“bA4”]/span[@class=“zF”]"

And i read your article above - and would like to have the TO being recognized with just few attributes needed… This is what makes me really sad and confused.

I know you can say - “hey Andrew - it runs, so forget about it”.

Unfortunately (or fortunately) - i always attempt to learn better…

Thank you very much!

Andrew

Well, at least now we have a better picture as to what is going on.

To me, this test scenario is ideally suited to building a dynamic test object “live” during the test case’s execution. The (bad) name attribute is consistent, so therefore I’d build the dynamic TO using just CSS (leave out the rest of that stuff which just causes confusion).

The CSS you need is:

span[name='CPL413000']

Read this article about modifying properties of TOs:

https://docs.katalon.com/display/KD/[WebUI]+Modify+Object+Property

Then create a dummy TO and modify its “css” property:

def tempTO = WebUI.modifyObjectProperty(findTestObject("dummy"), 
    "css", "equals", "span[name='CPL413000']", true)
WebUI.doSomething(tempTO)

(I typed that out from memory – double check for typos/errors)

I know you can say - “hey Andrew - it runs, so forget about it”.
Unfortunately (or fortunately) - i always attempt to learn better…

No, you’re absolutely right to keep going and not give up. If you shrug and walk away, what would you learn? B)

Good luck!

Russ

p.s. I’m surprised the developers are “good enough” to use data-* attributes for custom attributes yet they seem to have no issues with using a name attribute where it doesn’t belong (i.e. in a span). name attributes are typically applied to html form elements (and children) to create name/value pairs for http submission to a server – but spans are not submitted elements.

Furthermore, were you (or anyone) to devise a piece of css/jQuery selector/DOM selector using “[name]” e.g. document.querySelectorAll("[name]") , you’d get all the things you’re expecting (inputs, selects, etc) and a bunch of spans you are certainly not expecting. See? BAD. And like you said earlier, it works, forget about it… nope, I’d be scared that’s going to bite me one day and cost me a ton of time to figure what the hell is going on.

You might mention that to the developers and send them the MDN link. Suggest they use data-email-name, or similar. Thing is, the spec is what it is - a spec. It’s not a secret and it’s not a moving target (unlike bad code!)

End of rant B)

1 Like

Russ Thomas said:

Well, at least now we have a better picture as to what is going on.

To me, this test scenario is ideally suited to building a dynamic test object “live” during the test case’s execution. The (bad) name attribute is consistent, so therefore I’d build the dynamic TO using just CSS (leave out the rest of that stuff which just causes confusion).

The CSS you need is:

span[name='CPL413000']

Read this article about modifying properties of TOs:

https://docs.katalon.com/display/KD/[WebUI]+Modify+Object+Property

Then create a dummy TO and modify its “css” property:

def tempTO = WebUI.modifyObjectProperty(findTestObject("dummy"), 
"css", "equals", "span[name='CPL413000']", true)

WebUI.doSomething(tempTO)


(I typed that out from memory -- double check for typos/errors)  
  

> I know you can say - "hey Andrew - it runs, so forget about it".  
> Unfortunately (or fortunately) - i always attempt to learn better...  

  
No, you're absolutely right to keep going and not give up.  If you shrug and walk away, what would you learn?  B)  
  
Good luck!  
  
Russ  
  
p.s. I'm surprised the developers are "good enough" to use **data-*** attributes for custom attributes yet they seem to have no issues with using a **name** attribute where it doesn't belong (i.e. in a span). **name** attributes are typically applied to html form elements (and children) to create name/value pairs for http submission to a server -- _but spans are not submitted elements_.   
  
Furthermore, were you (or anyone) to devise a piece of css/jQuery selector/DOM selector using "\[name\]" e.g. document.querySelectorAll("\[name\]") , you'd get all the things you're expecting (inputs, selects, etc) and a bunch of spans you are certainly not expecting.  See? BAD.  And like you said earlier, it works, forget about it...  nope, I'd be scared that's going to bite me one day and cost me a ton of time to figure what the hell is going on.  
  
You might mention that to the developers and send them the MDN link.  Suggest they use **data-email-name**, or similar.  Thing is, the spec is what it is - a spec.  It's not a secret and it's not a moving target (unlike bad code!)  
  
End of rant B)  

  
  
  

  

Good Evening Russ

I have decided to take this one step forward and create Test Object via script.

TestObject dummy = new TestObject(‘dummy’)

dummy.addProperty(“css”, ConditionType.EQUALS, ‘span[name=“CPL413000”]’)

WebUI.verifyElementPresent(dummy, 10, FailureHandling.STOP_ON_FAILURE)

WebUI.verifyElementVisible(dummy, FailureHandling.STOP_ON_FAILURE)

However i believe i am missing an import package (i think), i am getting this command flagged:

ConditionType.EQUALS

So it errors this way:
Test Cases/TO_TEST FAILED because (of) Variable ‘ConditionType’ is not defined for test case.

Going to add a separate post for this.

Thank you
Andrew

AddProperty1.png

Actually - i went ahead and added the “dummy” Test Object manually.

And i have this command:
def tempTO = WebUI.modifyObjectProperty(findTestObject(‘dummy’, ‘css’, ‘equals’, ‘span[name=“CPL413000”]’, true))

However somehow it errors out:

Test Cases/TO_TEST FAILED because (of) groovy.lang.MissingMethodException: No signature of method: Script1529369104841.findTestObject() is applicable for argument types: (java.lang.String, java.lang.String, java.lang.String, java.lang.String, java.lang.Boolean) values: [dummy, css, equals, span[name=“CPL413000”], true]

Thank you
Andrew

Try …

... findTestObject("dummy") ...

But you could also dispense with the OR and create the TO “live”…

static TestObject makeTO(String css) {
  TestObject to = new TestObject()
  to.addProperty("css", ConditionType.EQUALS, css)
  return to
}

Source is “me” B) here: https://docs.katalon.com/display/KD/Creation+of+Test+Object+in+Object+Repository+in+Runtime