Ask a Question

Finding object by using dynamic xpath, using Partial Content text

muhammadA
Occasional Contributor

Finding object by using dynamic xpath, using Partial Content text

Hi all,

 

I have following dynamic xpath's

.//*[@id='1509527131388-grid-container']/div[2]/div
.//*[@id='1509528020936-grid-container']/div[2]/div
.//*[@id='1509528970483-grid-container']/div[2]/div
.//*[@id='1509528970483-grid-container']/div[2]/div

I am trying to find the object by

 

var obj = Sys.Browser("*").Page("*").FindChildByXPath(".//*[@id=150952'" + * + "'-grid-container']/div[2]/div]");

 

showing as syntax error. Can you please help me to find the error

17 REPLIES 17

Or you can use the title of the grid as anchor:

 

.//h4[text()="Basic Example"]/following::div[1]

Hi,

 

Thank you a lot for the link provided.

Fantastic example, directly from the product provider, of how the product can be created with the absolute ignorance of automated testing. Bookmarked.

 

The problem with all Angular controls that I've seen so far is that (by default?) they provide no unique and stable identifiers. The only entities that can be used to address UI elements is usually class name and visible text. I am pretty sure it is needless to say how unreliable this is.

 

Anyway, assuming that there is only one table on the page with the 'grid_container' identifier, personally I would do it like this:

-- search for the table container (tableContainer = page.FindChild(['ObjectType', 'ObjectIdentifier'], ['Panel', 'grid_container'], 10));

-- Using table container as the root, search for all 'uiGrid_0007_cell' elements that correspond to the data cells of the first column (arCells = tableContainer.FindAllChildren(['ObjectType', 'ObjectIdentifier'], ['Panel', 'uiGrid_0007_cell'], 10).toArray() ) (Note: the array will be in reverse order, i.e. the first array element will correspond to the last column cell - this is specific of how TestComplete's .FindAllChildren() method works);
-- Iterate through the returned array and get the value of the contentText property to get first column cell values.

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
muhammadA
Occasional Contributor

Thank you Alex. It was really good approach .

 

I executed the following code , please verify and I am getting JScript runtime error  'page' is undefined . Please correct me where I am going wrong. I attach screen shot

 

function VerifyGridValue(textValue)
{
  Sys.Browser("*").Page("*").Wait("10000");
  tableContainer = page.FindChild(['ObjectType', 'ObjectIdentifier'], ['Panel', 'grid_container'], 10);
 var Cells = tableContainer.FindAllChildren(['ObjectType', 'ObjectIdentifier'], ['Panel', 'uiGrid_0007_cell'], 10).toArray() ;
 console.log(Cells);
 
}

You should define page variable. 

 

page = Sys.Browser("*").Page("*")

In addition to the note by @baxatob:

.FindAllChildren() returns an array, thus while

console.log(Cells);

will work if executed from command line via cscript engine, the same line will fail in TestComplete as there is no console object.

You will need to either convert the array to string or iterate through it. Code example can be found, for example, here: http://support.smartbear.com/testcomplete/docs/reference/test-objects/members/common-for-all/findall...

Regards,
  /Alex [Community Hero]
____
[Community Heroes] 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. Posts made by [Community Heroes]
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.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================
vijaysimha
Occasional Contributor

Please illustrate an example on how to write dynamic xpaths in Testcomplete tool.

Ex: //*[@id='signout']/div[1]

vijaysimha
Occasional Contributor

Please illustrate an example on how to write dynamic xpaths as we use to write in Eclipse as ByXpath("//*[@id='signout']/div[1]") and if possible please make a video.

Ex: //*[@id='signout']/div[1]

You can test your xpath directly in your browser (e.g. using developer tools). If it works there, it will work also with TestComplete.

cancel
Showing results for 
Search instead for 
Did you mean: