cancel
Showing results for 
Search instead for 
Did you mean: 

FindChildByXPath is not working on the object created by EvaluateXPath method

Occasional Contributor

FindChildByXPath is not working on the object created by EvaluateXPath method

I created array of object by EvaluateXPath. When I loop to that object and use FindChildByXPath, not supporting this method error is appearing.

Here in the code.

 

 

var obj1 = MyWebpageObject.EvaluateXPath("//ul[@id='UserList']/li");
var arrObj = obj1.toArray();
for (var i in arrObj){
var objDate = arrObj[i].FindChildByXPath("//span[@id,'txt-date']")
if(objDate)
{
  BuiltIn.ShowMessage(objDate.contentText)
}

 

When it is executing arrObj[i].FindChildByXPath, throwing an error as "Object doen't support this propertyt or method"

 

 

 

3 REPLIES 3
Highlighted
Community Hero

Re: FindChildByXPath is not working on the object created by EvaluateXPath method

Hi,

 

This behaviour is explained in the https://support.smartbear.com/testcomplete/docs/reference/test-objects/members/page/findchildbyxpath... help topic section. Namely:

If several elements match the search condition, the function returns the first found object that resides in the Object Tree. If none of the found objects resides in the Object Tree, the function returns the first element from the found set.


The above means that some or all objects found by .EvaluateXPath() are absent in the Object Tree and thus they are not wrapping objects provided by TestComplete (containing the .FindChildByXPath() method) but native DOM objects and you can use only native methods provided by DOM for the given found object.

 

Note: the above means that not only .FindChildByXPath() method is absent for the native DOM objects, but none of methods and properties that are provided by TestComplete. For example, objDate.Exists cannot be used as well.

 

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================
Occasional Contributor

Re: FindChildByXPath is not working on the object created by EvaluateXPath method

Thanks for the replay.

In that case how can I get properties of some child object created by FindChildByXPath with xpath. For example,

if I have multple dom with a class name in the dom, I need to check the some properties inside object with xpath 

 

 

<ul>
	<li class = "some Class">
		<span class = "some calss2">
			text
		</span>
	</li>
	<li>
	...
	</li>
	...
</ul>

 

now I am creating object by using //li[@class='val']

In case if I need use childobject, of //span[@class='val'] in each object, how can I do the same with Testcomplete tool

 

 

Community Hero

Re: FindChildByXPath is not working on the object created by EvaluateXPath method

Hi,

 

HTML markup provided by you is very poor one because it does not contain any stable unique identifier.

If you really need to work with web pages that generate markup like you've provided, then you may do it this way:

-- Check if the found object is TestComplete wrapping one. This can be done using the code like this:

if (aqObject.IsSupported(<object>, 'Exists')) then // this is TestComplete object

 

-- If the found object is TestComplete wrapping one, you may use methods provided by TestComplete (like you tried);

-- If the found object appeared to be native DOM one, then you should use native DOM functions like selectSingleNode(), selectNodes(), etc. and continue to work with the found child objects as with native DOM objects.

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms757828%28v%3dvs.85%29

https://docs.microsoft.com/en-us/previous-versions/windows/desktop/ms764730(v=vs.85)

https://stackoverflow.com/questions/16016521/how-do-i-select-child-elements-of-any-depth-using-xpath

 

Regards,
Alex
[Community Expert Group]
____
[Community Expert Group] members are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Postings made by [Community Expert Group] members
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
[Community Expert Group] signature is used with permission by SmartBear Software.
http://smartbear.com/forums/f83/t86934/community-experts/
================================