Page 1 of 1

How can I set innertext of the object using ranorex user code

Posted: Fri Mar 06, 2020 6:10 am
by Tushar
I added an object in the repo and assigned innertext as Regex with .*
Now through user code I am assigning an innertext as -

repo.objectName.Element.SetAttributeValue("InnerText", dataTransform)

And then I am trying to see if it is visible or not by =

Dim dataTransformObj As Ranorex.WebElement = repo.objectName

If dataTransformObj.visible() Then
'Passed
End If


However this is not working. Seems like innertext is not setting up while test execution, please help!

Re: How can I set innertext of the object using ranorex user code

Posted: Fri Mar 06, 2020 8:26 am
by odklizec
Hi,

Have you tried to set the value via SetValue action in Recording? Just to eliminate a potential code error?

A most probable reason of problem like this is, that the input in question requires "on-key" event to trigger the change. SetAttributeValue action unfortunately does not trigger such event. Try to use KeySequence action (PressKeys method) instead.

Code: Select all

repo.objectName.Element.PressKeys(dataTransform);
BTW, I would strongly recommend to not reference repo element directly in code and rather use RepoItemInfo/Adapter parameter to pass the repo elements to method of your choice.

Code: Select all

public static void CustomMethod(RepoItemInfo repoElement)
{
     repoElement.CreateAdapter<Ranorex.Unknown>(false).PressKeys(dataTransform);
}
Referencing repo elements directly in code, may look easier, but from the long-term perspective, it's a bad habit ;)

Re: How can I set innertext of the object using ranorex user code

Posted: Fri Mar 06, 2020 9:28 am
by Tushar
Thanks for your solution.

The statement below is not supported as I want to change the runtime value of the WebElement present in Object Repository.

Code: Select all

repo.objectName.Element.PressKeys(dataTransform);
Basically I want to reuse the dynamic objects whose innertext changes during each run.

Now in UFT, I use 'SetTOProperty' to set runtime value of the object.

The recording is not feasible as I want to create custom function to achieve this.

Is there any way I can assign innertext value to object during runtime? Please refer Image

Re: How can I set innertext of the object using ranorex user code

Posted: Fri Mar 06, 2020 9:35 am
by odklizec
Hi,

I asked you to use SetValue action in recording, just to confirm or deny that the SetValue is working with the element in question. As I mentioned, SetValue/SetAttributeValie is most probably not supported by the input in question and so there must be use Key-based action.

Please post a Ranorex snapshot (NOT screenshot) of the problematic element. Ideally, post also a small HTML sample, featuring the input in question. It does not have to be entire production page, just the input element. But it must be implemented the same way as on tested page.