What is Webtable?
Web tables are basically group of elements that are logically stored in a row and column format.
Web tables are basically group of elements that are logically stored in a row and column format.
- If we know that number or rows and Columns are fixed than we will use the below approach
1 | for ( int numberOfRows= 1 ; numberOfRows<= 5 ; numberOfRows++) |
2 | { |
3 | for ( int numberOfCol= 1 ; numberOfCol <= 3 ; numberOfCol++) |
4 | { |
5 | System.out.println(driver.findElement(By.xpath(“ //div[@id='main']/table[1]/tbody/tr[“+numberOfRows+”]/th[“+numberOfCol+”]”))); |
6 | } |
7 | } |
- How to work with the dynamically changed webtables?
1 | WebElement htmltable=driver.findElement(By.xpath( "//*[@id='main']/table[1]/tbody" )); |
2 | List<WebElement> rows=htmltable.findElements(By.tagName( "tr" )); |
3 |
4 | for ( int rnum= 0 ;rnum<rows.size();rnum++) |
5 | { |
6 | List<WebElement> columns=rows.get(rnum).findElements(By.tagName( "th" )); |
7 | System.out.println( "Number of columns:" +columns.size()); |
8 |
9 | for ( int cnum= 0 ;cnum<columns.size();cnum++) |
10 | { |
11 | System.out.println(columns.get(cnum).getText()); |
12 | } |
13 | } |
No comments:
Post a Comment