How to fetch Xpath for a dynamic table

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
raghupokuri
Posts: 2
Joined: Fri Jan 31, 2014 7:11 am

How to fetch Xpath for a dynamic table

Post by raghupokuri » Wed Feb 05, 2014 1:34 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to fetch Xpath for a dynamic table

Post by Support Team » Fri Feb 07, 2014 3:37 pm

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

rholdberh
Posts: 27
Joined: Mon Jan 13, 2014 3:45 pm

Re: How to fetch Xpath for a dynamic table

Post by rholdberh » Tue Feb 11, 2014 3:50 pm

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?
You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to fetch Xpath for a dynamic table

Post by Support Team » Thu Feb 13, 2014 1:35 pm

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

rholdberh
Posts: 27
Joined: Mon Jan 13, 2014 3:45 pm

Re: How to fetch Xpath for a dynamic table

Post by rholdberh » Fri Feb 14, 2014 11:22 am

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: How to fetch Xpath for a dynamic table

Post by Support Team » Fri Feb 14, 2014 3:29 pm

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
You do not have the required permissions to view the files attached to this post.

mzperix
Posts: 137
Joined: Fri Apr 06, 2012 12:19 pm

Re: How to fetch Xpath for a dynamic table

Post by mzperix » Thu Mar 13, 2014 9:59 am

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']