Tuesday, January 26, 2016

Find text in table without table iteration

Normally we follow the approach of iterating table, find the required text and perform some operation on same row. This approach is fast for small table but when it comes to very large table iteration will be slow enough.

Instead without iterating the table find the text using xpath and perform operation on same row.

Let take an example:









From above table we want 'Travel' time (column = 7) of particular train from 'Train No' (column=1).

String travelTime = driver.findElement(
By.xpath("//table[@id='trainInfo']/tbody/tr/td[text()='19215']/../td[7]")).getText();

OUTPUT:
Travel time: 15.35

No comments:

Post a Comment