-1

My xpath =

".//*[@id='ctl00_ctl00_MainContent_ChildContent1_frmClear_dgCashed']/tbody/tr[67]]/td[1]/strong"

where value 67 keeps on changing. How can i use Regular expression so that i can read the value of this element?

Please Need help,Thanks

Abdul Hameed
  • 1,135
  • 1
  • 13
  • 24
Rakesh Kumar
  • 19
  • 1
  • 6
  • Can any one please help me, – Rakesh Kumar Jan 26 '16 at 21:30
  • So your problem is that you never know which table row your data is in? Sometimes roe 67, sometimes elsewhere? I can't see how a RegEx could help you with that. Is there anything constant about the element you try to locate? – Würgspaß Jan 26 '16 at 21:53
  • Hi, the whole xpath is constant, except the number 67, if i can use regular expression , for 67 , than i can read the value . – Rakesh Kumar Jan 26 '16 at 21:54
  • Actually element text field value = "Total :67" so the xpath is ".//*[@id='ctl00_ctl00_MainContent_ChildContent1_frmClear_dgCashed']/tbody/tr[67]]/td[1]/strong" – Rakesh Kumar Jan 26 '16 at 21:56
  • the total value is changing depends on the number of values in the table, irrespective of that i want to read the value – Rakesh Kumar Jan 26 '16 at 21:57
  • To clarify my question the element is "Total :67" its xpath is ".//*[@id='ctl00_ctl00_MainContent_ChildContent1_frmClear_dgCashed']/tbody/tr[67]]/td[1]/strong". – Rakesh Kumar Jan 26 '16 at 22:03
  • Ok, so the number of rows in the table is dynamic. RegEx (like a wildcard) doesn't help because you don't want to find the first element that matches but retrieve the value of the last row, right? So, you should retrieve the number of rows from the text field which says _value = "Total :67_ Can you edit your question and post the HTML code of that text field? – Würgspaß Jan 26 '16 at 22:04
  • There are currently 67 rows , which i snot constant, it may change , but i would like to read the value even though the no of rows changes . pls need help – Rakesh Kumar Jan 26 '16 at 22:04
  • I am attaching the screenshot where it shows the value – Rakesh Kumar Jan 26 '16 at 22:06
  • sorry i could not attach the screenshot , not showing any option to attach – Rakesh Kumar Jan 26 '16 at 22:09
  • 1
    Screenshots don't help. Please paste the snippet of HTML code (as edit to your question, not as a comment). – Würgspaß Jan 26 '16 at 22:10

2 Answers2

1

As I don't know your HTML, it's not completely clear to me what you're trying to achieve. But if you say you want to find row #67 and the total number is also 67, then I assume you are trying to find the last row in the table!?

If this is case, instead of stating tr[67], you should simply use tr[last()].

Kim Homann
  • 3,042
  • 1
  • 17
  • 20
0

The below link is similar one as discussed,

how to pass value from valraible in to xpath

public void selectTableRow(String v) throws Exception {
try {
driver.findElement(By.xpath("".//*[@id='ctl00_ctl00_MainContent_ChildContent1_frmClear_dgCashed']/tbody/tr["+v+"]]/td[1]/strong".click();
 }
 catch (AssertionError Ae)
{
 Ae.printStackTrace();
 }
}
Anitha
  • 38
  • 7
  • Thanks, but my question is xpath : ".//*[@id='ctl00_ctl00_MainContent_ChildContent1_frmClear_dgCashed']/tbody/tr[67]]/td[1]/strong" this value 67 is dynamic , i want to have regular expressioon so that i can read the value from xpath which i can use it ....so i need your help – Rakesh Kumar Jan 27 '16 at 14:55