int r = selenium.getXpathCount("//table[@id='tblDetail']/tbody/tr[.]/td[1]");

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

int r = selenium.getXpathCount("//table[@id='tblDetail']/tbody/tr[.]/td[1]");

Illusion0Reality
Seems, I posted in wrong place. If so, please move to the appropriate forum.


 int r = selenium.getXpathCount("//table[@id='tblDetail']/tbody/tr[.]/td[1]");

What does tr[.] mean, please let me know.

And getXpathCount = driver.findElements(By.id("ssss")).size - Am I right?




Reply | Threaded
Open this post in threaded view
|

Re: int r = selenium.getXpathCount("//table[@id='tblDetail']/tbody/tr[.]/td[1]");

softwaretestingforum
Administrator
Good question.

In xpath . points to current node while .. points to parent node
Let's take example from w3school site - http://www.w3schools.com/html/html_tables.asp

Here Apples row data could be reached as -

$x("//div[@class='example']/table[@class='reference']//tr[1]/td[contains(text(), 'Apples')]")

or -

$x("//div[@class='example']/table[@class='reference']//tr[.]/td[contains(text(), 'Apples')]")

More over you can reach row data - 'other' with out hard coding tr count -

$x("//div[@class='example']/table[@class='reference']//tr[.]/td[contains(text(), 'Other')]")

Hence using . gives you more flexibility and would identify the element even if there row position is changed. This is also known as context node. Notice that you can also write last statement as -

$x("//div[@class='example']/table[@class='reference']//tr[.]/td[contains(., 'Other')]")

hence word 'Other' is matched against any context node. It does not have to be only text - it could be id, name or any other attribute.

A good read on this - http://oreilly.com/perl/excerpts/system-admin-with-perl/ten-minute-xpath-utorial.html 
~ seleniumtests.com
Reply | Threaded
Open this post in threaded view
|

Re: int r = selenium.getXpathCount("//table[@id='tblDetail']/tbody/tr[.]/td[1]");

Illusion0Reality
Thanks Tarun, for the elaborate answer.

And, - selenium.getXpathCount = driver.findElements(By.id("ssss")).size - Am I right?

Regards
Reply | Threaded
Open this post in threaded view
|

Re: int r = selenium.getXpathCount("//table[@id='tblDetail']/tbody/tr[.]/td[1]");

softwaretestingforum
Administrator
Exactly the only difference is - you use <By.id("ssss")> to find the number of elements.
hence you not limited to just using xpath, you could use any element locator you want to.
~ seleniumtests.com