Re: [selenium-users] Can't use an integer variable in place of integer in xpath

102 views
Skip to first unread message

Hien Ngo

unread,
Jun 19, 2012, 3:23:38 PM6/19/12
to seleniu...@googlegroups.com
I believe Xpath search engine doesn't know when the "i" is a variable and when it is an actual i as in "yui". Use this tr[Myvar] in place off tr[i], and excute command MyXpath.replace(Myvar, i.tostring());

On Tue, Jun 19, 2012 at 12:10 PM, carina0110 <intern...@hotmail.com> wrote:
(Using Webdriver / Java / Eclipse / TestNG)
 
I want to work with a row item in a table. I'm going through the rows using a loop where my counter is declared and initialized as 'int row = 1'.
 
The element declaration is as follows:

driver.findElement(By.xpath(".//*[@class='yui3-datatable-data']/tr[i]/td[contains(@class,'yui3-datatable-col-tmpt_name')]"))

Notice the "tr[i]" part of the xpath. If I use the integer varable 'i', I can't get the text. If I use actual integer, "tr[1]", I get the text just fine. Why?
 
I tried changing the type to 'long', but it's not working.
 
Thanks.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/JqSrn_27Yi4J.
To post to this group, send email to seleniu...@googlegroups.com.
To unsubscribe from this group, send email to selenium-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/selenium-users?hl=en-US.

Mike Riley

unread,
Jun 19, 2012, 5:01:12 PM6/19/12
to seleniu...@googlegroups.com
It is much easier than that.  I do this all the time:
driver.findElement(By.xpath(".//*[@class='yui3-datatable-data']/tr[" + i + "]/td[contains(@class,'yui3-datatable-col-tmpt_name')]"))

Java will convert the integer to a string for you automagically.

Mike


On Tuesday, June 19, 2012 12:23:38 PM UTC-7, Lerry wrote:
I believe Xpath search engine doesn't know when the "i" is a variable and when it is an actual i as in "yui". Use this tr[Myvar] in place off tr[i], and excute command MyXpath.replace(Myvar, i.tostring());

On Tue, Jun 19, 2012 at 12:10 PM, carina0110 <intern...@hotmail.com> wrote:
(Using Webdriver / Java / Eclipse / TestNG)
 
I want to work with a row item in a table. I'm going through the rows using a loop where my counter is declared and initialized as 'int row = 1'.
 
The element declaration is as follows:

driver.findElement(By.xpath(".//*[@class='yui3-datatable-data']/tr[i]/td[contains(@class,'yui3-datatable-col-tmpt_name')]"))

Notice the "tr[i]" part of the xpath. If I use the integer varable 'i', I can't get the text. If I use actual integer, "tr[1]", I get the text just fine. Why?
 
I tried changing the type to 'long', but it's not working.
 
Thanks.

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/selenium-users/-/JqSrn_27Yi4J.
To post to this group, send email to selenium-users@googlegroups.com.
To unsubscribe from this group, send email to selenium-users+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages