Selenium getting the table cell data for HTML

Source: Internet
Author: User
Tags tagname

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.