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

Ask general questions here.
Tushar
Posts: 7
Joined: Wed Feb 12, 2020 1:40 pm

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

Post by Tushar » Fri Mar 06, 2020 6:10 am

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!

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6181
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Mar 06, 2020 8:26 am

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 ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

Tushar
Posts: 7
Joined: Wed Feb 12, 2020 1:40 pm

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

Post by Tushar » Fri Mar 06, 2020 9:28 am

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
Attachments
Image 1.png
Image 1.png (19.39 KiB) Viewed 171 times

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 6181
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

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

Post by odklizec » Fri Mar 06, 2020 9:35 am

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration