How to convert string to divtag

Class library usage, coding and language questions.
sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

How to convert string to divtag

Post by sham526 » Fri Aug 27, 2010 6:28 am

Hi,
i am having a string which has some path like

Dim chb_str as string ="/dom[@domain='............................................./div/div"
Dim name as string="Asia"
Dim rxp As New Rxpath(path_div)
Dim main_path as DivTag = rxp
Dim child_atag As Ranorex.ATag = main_path.FindSingle(Of Ranorex.ATag)("./div/div/table/tbody/tr/td/a[@InnerText='"+name.ToString+"']")


now i am getting an error as below

System.NullReferenceException: Object reference not set to an instance of an object.
at Ranorex.Core.Path.LocationStep..ctor(ITree stepTree, RxPath owner)
at Ranorex.Core.RxPath.TryInit(String path)
--- End of inner exception stack trace ---
at Ranorex.Core.RxPath..ctor(String path)

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to convert string to divtag

Post by Support Team » Fri Aug 27, 2010 10:23 am

Which of the RxPaths in your code causes the problem? The first one (chb_str) or the one passed to the FindSingle method?
Which Ranorex version do you use?

Please, post the complete RxPath that causes the exception and the complete exception text (seems like the exception message you posted is taken from the inner exception only)!

Regards,
Alex
Ranorex Team
.
Image

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: How to convert string to divtag

Post by sham526 » Fri Aug 27, 2010 1:58 pm

Dim chb_str as string ="/dom[@domain='............................................./div/div"
Dim name as string="Asia"
Dim item As Ranorex.ATag = Nothing
Dim child_name As String = name.ToString
Dim rxp As RxPath = path_div
Dim child_atag As Ranorex.ATag = rxp.FindSingle(Of Ranorex.ATag)("./div/div/table/tbody/tr/td/a[@InnerText='"+name.ToString+"']")
Dim rxpath as String = child_atag.GetPath().ToString
Dim a_found As Boolean =main_divtag.TryFindSingle(rxpath,item)
If a_found Then
------
else
------

getting an error that Findsingle is not a member of Ranorex.core.Rxpath

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to convert string to divtag

Post by Support Team » Sat Aug 28, 2010 11:44 am

sham526 wrote:getting an error that Findsingle is not a member of Ranorex.core.Rxpath
...because you cannot invoke FindSingle on a path, only on an element. You have to search for "rxp" first, e.g. by assigning it to an element variable:
Dim rxp As String = "your RanoreXPath"
Dim divTag As DivTag = rxp
Dim child_atag As Ranorex.ATag = rxp.FindSingle(...)
I suggest reading the Ranorex Tutorial and a few chapters in the Ranorex User Guide, especially this one:
http://www.ranorex.com/support/user-gui ... apter.html

Regards,
Alex
Ranorex Team
.
Image

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: How to convert string to divtag

Post by sham526 » Mon Aug 30, 2010 6:07 am

I tried that one also.

Dim chb_str as string ="/dom[@domain='............................................./div/div"
Dim name as string="Asia"
Dim rxp As New Rxpath(path_div)
Dim main_path as DivTag = rxp
Dim child_atag As Ranorex.ATag = main_path.FindSingle(Of Ranorex.ATag)("./div/div/table/tbody/tr/td/a[@InnerText='"+name.ToString+"']")


now i am getting an error as below for the line =======> Dim main_path as DivTag = rxp

System.NullReferenceException: Object reference not set to an instance of an object.
at Ranorex.Core.Path.LocationStep..ctor(ITree stepTree, RxPath owner)
at Ranorex.Core.RxPath.TryInit(String path)
--- End of inner exception stack trace ---
at Ranorex.Core.RxPath..ctor(String path)

sham526
Posts: 34
Joined: Wed Jul 07, 2010 7:12 am
Location: Hyderabad(INDIA)

Re: How to convert string to divtag

Post by sham526 » Mon Aug 30, 2010 6:12 am

I did this but its showing the error

Value of type 'Ranorex.Core.RxPath' cannot be converted to 'Ranorex.DivTag'. (BC30311)

Dim rxp As RxPath = path_div
Dim div_path As DivTag = rxp
Dim child_atag As Ranorex.ATag = div_path.FindSingle(Of Ranorex.ATag)("./div........")

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: How to convert string to divtag

Post by Support Team » Mon Aug 30, 2010 9:02 am

From your code I can't see where the path_div variable is defined; could it be that this variables is not defined or null? The following code is working for me, you just have to insert the right RanoreXPath to your DIV tag in the first code line:
Dim path_div as string ="your RanoreXPath to the DIV tag"
Dim name as string="Asia"
Dim divTag_adapter as DivTag = path_div
Dim child_atag As Ranorex.ATag = divTag_adapter.FindSingle(Of Ranorex.ATag)("./div/div/table/tbody/tr/td/a[@InnerText='"+name.ToString+"']")
Please, consider reading the Ranorex Tutorial! I posted the link to it in my last post and a link to the Ranorex User Guide.

Another hint: I guess that you have switched off the "Explicit" option in your VB project settings. If you switch the "Explicit" option on, you might get better error messages.

Regards,
Alex
Ranorex Team
.
Image