Selenium Webdriver Processing Table

Source: Internet
Author: User

First, theHTML table is composed of a TABLE element and one or more tr,th , or The TD element is composed.

For example:

This is a simple HTML table:

The source code is as follows:

So the question is, I want to get the value of each cell of this table through XPath (for example, get expect value), what to do.

If this table is changed, how do I add or remove a number of columns?

My solution is to get the base XPathof the table, this so-called base XPath Refers to the same portion of column m of row n of this table , and then passes in the n,m Get return value

public static string TableCell (Webdriver driver,int row, int column) {string text = null;            Avoid get the head line of the table row=row+1;        String xpath= "//*[@id = ' table138 ']/tbody/tr[" +row+ "]/td[" +column+ "]"; Webelement table=driver.findelement (By.xpath (XPath));        *[@id = "table138"]/tbody/tr[1]/td[1]/strong text=table.gettext ();            return text; }

So,TableCell (driver,1,2) will be able to return

Selenium Webdriver Processing Table

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.