Page 1 of 1

How to fetch Xpath for a dynamic table

Posted: Wed Feb 05, 2014 1:34 pm
by raghupokuri
Hi,

My Scenario:- have a grid table in flex application after adding one item rows will increment ,but i want to check the checkbox which is in second row.

table will getting updated regulalry i want to identify the element for a particular row

Thanks
Raghu
+91 9035806081

Re: How to fetch Xpath for a dynamic table

Posted: Fri Feb 07, 2014 3:37 pm
by Support Team
Hi,

Unfortunately I’m afraid that I don’t understand your problem. Please explain it in more detail.
If you want to access a specific row you can e.g. use an index:

Code: Select all

/table[@id='Sample']/row[@index='2']
Regards,
Robert

Re: How to fetch Xpath for a dynamic table

Posted: Tue Feb 11, 2014 3:50 pm
by rholdberh
Hi, have also a problem with grid table. I have a dynamic table with the list of items. My scenario is that i want to add item, and work with the row where item present, that means to click button in this particular row.
As u see from my snapshot:
div 'ui-widget-content slick-row even zebra' is the first row with those items
div 'ui-widget-content slick-row odd zebra' is the second row

i want to focus for example on a row with div '14021151440587' (first row) and work with it. I need to store some how Xpath position to this row.

Any ideas?

Re: How to fetch Xpath for a dynamic table

Posted: Thu Feb 13, 2014 1:35 pm
by Support Team
Hi,

There are different ways how you can identify the specific row.
One is to use the class attribute, in the case this attribute uniquely identidies the specific row:

Code: Select all

.../div[@class~'.*even zebra']
another way is to use the unique RxPath to the child element to uniquely identify its parent element:

Code: Select all

/dom[@domain='localhost:40003']//div[#'formerExportsTable']/div//div[@innertext='140211151440587']/../../div[@class~'.*even zebra']
For more information about the RxPath please see: RanoreXPath and RanoreXPath – Tips and Tricks.

Regards,
Markus

Re: How to fetch Xpath for a dynamic table

Posted: Fri Feb 14, 2014 11:22 am
by rholdberh
yeee but i want to do that:
1. find an element in the table
2. focus on a row with this elemnt
3.press button in this row

Like i cant specify the row because next time it wont be on the same position. I need to store this row, and use this row for next commands

Re: How to fetch Xpath for a dynamic table

Posted: Fri Feb 14, 2014 3:29 pm
by Support Team
Hi,

I have created a small sample solution, based on your snapshot which should fullfill all your requirements. :wink:
public void ClickButton()
{
	//You get a Div tag without knowing the row just the innertext of the element
	DivTag element1 = @"/dom[@caption='Tryit Editor v1.8']/body//div[@InnerText~'.*element 1.']";
	//The row in your data structure is always the parent Div Tag of the element.
	DivTag row = element1.Parent.As<DivTag>();
	Report.Info("Row: " + row.Id.ToString());
	//Press button in this row
	ButtonTag button = row.FindSingle<ButtonTag>(@".//button[@innertext='Click']");
	button.Click();
}
Please have a look at the attached snapshot file aswell.

Regards,
Robert

Re: How to fetch Xpath for a dynamic table

Posted: Thu Mar 13, 2014 9:59 am
by mzperix
We encounter this problem often. What we do is to write a proper Xpath for the button we need to click.

based on your snapshot, if you want to click on the Download button of the row that contains the Text '140211151440587':

Code: Select all

 /dom[@domain='localhost:40003']//div[#'formerExportsTable']//div[@innertext='140211151440587']/..//button[@innertext='Download']
the /../ part is to tell xpath to go up one level in the spy hierarchy, so we can search the download button from there down below.

You can also paramterize the xpath to look for a text that you can set from a variable ($yourparameter):

Code: Select all

 /dom[@domain='localhost:40003']//div[#'formerExportsTable']//div[@innertext=$yourparameter]/..//button[@innertext='Download']