Get the value of a cell in a table of a Web page, directly on the code as follows:
Packagecom.table;Importjava.util.List;Importorg.openqa.selenium.By;ImportOrg.openqa.selenium.WebDriver;Importorg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.chrome.ChromeDriver;/*** @ClassName: TestTable * @Description: TODO (Get the value of a cell in a table) *@authorQiaojiafei * @date December 4, 2015 morning 10:32:44 **/ Public classtesttable {Webdriver Dr=NULL; Public voidinit () {System.setproperty ("Webdriver.chrome.bin", "D:/baiduyundownload/selenium/chromedriver.exe"); Dr=NewChromedriver (); Dr.get ("File:///D:/testhtml/table.html"); } Public voidTearDown () {dr.quit (); } PublicList<webelement>GetRow () {webelement e_table= Dr.findelement (By.id ("MyTable")); List<WebElement> E_row = e_table.findelements (By.tagname ("tr")); inti =e_row.size (); //System.out.println (i); returnE_row; } PublicWebelement Getcell (list<webelement> List,intRown,intColn) {List<WebElement> E_col = List.get (rowN-1) findelements (By.tagname ("TD")); returnE_col.get (colN-1); } PublicString Gettalbevalue (intRown,intColn) {String s=Getcell (GetRow (), Rown, Coln). GetText (); returns; } Public Static voidMain (String args[]) {testtable TT=Newtesttable (); Tt.init (); System.out.println (Tt.gettalbevalue (2, 1)); }}
Selenium getting the table cell data for HTML