{"id":106339,"date":"2020-08-18T10:00:00","date_gmt":"2020-08-18T07:00:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=106339"},"modified":"2020-08-10T15:19:45","modified_gmt":"2020-08-10T12:19:45","slug":"how-to-handle-web-table-in-selenium-webdriver","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html","title":{"rendered":"How To Handle Web Table in Selenium WebDriver?"},"content":{"rendered":"<p>Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either be static or dynamic in nature. You\u2019d often see such examples in e-commerce portals, where product specifications are displayed in a web table. With its wide use, you\u2019d often come across scenarios where you\u2019ll need to handle them in your <a href=\"https:\/\/www.lambdatest.com\/selenium-automation\" target=\"_blank\" rel=\"noopener noreferrer\">Selenium test automation<\/a> scripts.<\/p>\n<p>In this Selenium WebDriver tutorial, I\u2019ll take a look at how to handle a web table in Selenium along with a few useful operations that can be performed on web tables. By the end of this tutorial, you\u2019ll gain a thorough understanding of web tables in Selenium test automation along with methodologies used to access content in the web table. To know more about <a href=\"http:\/\/lambdatest.com\/selenium\" target=\"_blank\" rel=\"noopener noreferrer\">What is Selenium<\/a>, you can refer to our detailed page on the topic.<\/p>\n<p>Below are the sub-topics covered as a part of this <a href=\"https:\/\/www.lambdatest.com\/blog\/selenium-webdriver-tutorial-for-cross-browser-testing\/\" target=\"_blank\" rel=\"noopener noreferrer\">Selenium WebDriver tutorial<\/a>:<\/p>\n<h2 class=\"wp-block-heading\">What is a Web Table in Selenium?<\/h2>\n<p>Web table in <a href=\"https:\/\/www.lambdatest.com\/selenium\" target=\"_blank\" rel=\"noopener noreferrer\">Selenium<\/a> is a WebElement just like any other popular WebElements like text boxes, radio buttons, checkboxes, drop-down menus, etc. Web table and its contents can be accessed by using the WebElement functions along with locators to identify the element (row\/column) on which the operation needs to be performed.<\/p>\n<p>A table consists of rows and columns. The table created for a web page is called a web table. Below are some of the important tags associated with a web table:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>&lt; table &gt;<\/strong> \u2013 Defines an HTML table<\/li>\n<li><strong>&lt; th &gt;<\/strong> \u2013 Contains header information in a table<\/li>\n<li><strong>&lt; tr &gt;<\/strong> \u2013 Defines a row in a table<\/li>\n<li><strong>&lt; td &gt;<\/strong> \u2013 Defines a column in a table<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">Types of Web Tables in Selenium<\/h2>\n<p>There are two broad categories of tables namely:<\/p>\n<h2 class=\"wp-block-heading\"><b>Static Web Table <\/b><\/h2>\n<p>As the name indicates, the information in the table is static in nature.<\/p>\n<h2 class=\"wp-block-heading\"><b>Dynamic Web Table<\/b><\/h2>\n<p>The information displayed in the table is dynamic. E.g. Detailed Product information on e-commerce websites, sales reports, etc.<\/p>\n<p>For the demonstration to handle the table in Selenium, we make use of a table that is available in the <a href=\"https:\/\/www.w3schools.com\/html\/html_tables.asp\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">w3school HTML table<\/a> page. Though there are fewer cross browser testing issues when using tables, some of the <a href=\"https:\/\/caniuse.com\/#search=HTML%20table\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">old browser versions<\/a> of Internet Explorer, Chrome, and other web browsers do no support HTML Table APIs.<\/p>\n<p>Now that we\u2019ve covered the basics, next in this Selenium WebDriver tutorial, I\u2019ll take a look at some of the frequently used operations to handle tables in Selenium that would help in your Selenium test automation efforts.<\/p>\n<h2 class=\"wp-block-heading\">Handling Web Tables in Selenium<\/h2>\n<p>I\u2019ll use the local Selenium WebDriver for performing browser actions to handle table in Selenium, present on <a href=\"https:\/\/www.w3schools.com\/html\/html_tables.asp\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">w3schools html table<\/a> page. The HTML code for the web table used for demonstration is available in the <a href=\"https:\/\/www.w3schools.com\/html\/tryit.asp?filename=tryhtml_table_intro\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">tryit adapter<\/a> page.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Handling-Web-Tables.png\" alt=\"\" class=\"wp-image-106363\" width=\"641\" height=\"214\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Handling-Web-Tables.png 854w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Handling-Web-Tables-300x100.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Handling-Web-Tables-768x256.png 768w\" sizes=\"(max-width: 641px) 100vw, 641px\" \/><\/figure>\n<\/div>\n<p>The Selenium WebDriver for popular browsers can be downloaded from the locations mentioned below:<\/p>\n<figure class=\"wp-block-table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p>&nbsp;<\/p>\n<p><span> Browser<br \/><\/span><\/p>\n<\/th>\n<th>\n<p>&nbsp;<\/p>\n<p><span> Download location<br \/><\/span><\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p>Opera<\/p>\n<\/td>\n<td>\n<p><a href=\"https:\/\/github.com\/operasoftware\/operachromiumdriver\/releases\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/github.com\/operasoftware\/operachromiumdriver\/releases<\/a><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Firefox<\/p>\n<\/td>\n<td>\n<p><a href=\"https:\/\/github.com\/mozilla\/geckodriver\/releases\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/github.com\/mozilla\/geckodriver\/releases<\/a><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Chrome<\/p>\n<\/td>\n<td>\n<p><a href=\"http:\/\/chromedriver.chromium.org\/downloads\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">http:\/\/chromedriver.chromium.org\/downloads<\/a><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Internet Explorer<\/p>\n<\/td>\n<td>\n<p><a href=\"https:\/\/github.com\/SeleniumHQ\/selenium\/wiki\/InternetExplorerDriver\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/github.com\/SeleniumHQ\/selenium\/wiki\/InternetExplorerDriver<\/a><\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p>Microsoft Edge<\/p>\n<\/td>\n<td>\n<p><a href=\"https:\/\/blogs.windows.com\/msedgedev\/2015\/07\/23\/bringing-automated-testing-to-microsoft-edge-through-webdriver\/\" target=\"_blank\" rel=\"noopener nofollow noreferrer\">https:\/\/blogs.windows.com\/msedgedev\/2015\/07\/23\/bringing-automated-testing-to-microsoft-edge-through-webdriver\/<\/a><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/figure>\n<p>I\u2019ll use the Python unittest framework to handle tables in <a href=\"https:\/\/www.lambdatest.com\/selenium#selenium-webdriver\" target=\"_blank\" rel=\"noopener noreferrer\">Selenium WebDriver<\/a>. The core logic for accessing elements in web tables still remains the same even if you are using other programming languages for Selenium test automation.<\/p>\n<p>Note \u2013 Implementation in the setUp() and teardown() remains the same for all the scenarios. We would not repeat that section in every example being shown in the blog.<\/p>\n<h3 class=\"wp-block-heading\">Handling Number Of Rows &amp; Columns In Web Table<\/h3>\n<p>The <code>&lt; tr &gt;<\/code> tag in the table indicates the rows in the table and that tag is used to get information about the number of rows in it. Number of columns of the web table in Selenium are calculated using XPath (\/\/*[@id=\u2019customers\u2019]\/tbody\/tr[2]\/td). XPath of the rows and columns are obtained using the inspect tool in the browser to handle tables in Selenium for <a href=\"https:\/\/www.lambdatest.com\/selenium-automation\" target=\"_blank\" rel=\"noopener noreferrer\">automated browser testing<\/a>.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/automated-browser-testing-1-1024x537.png\" alt=\"\" class=\"wp-image-106365\" width=\"768\" height=\"403\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/automated-browser-testing-1-1024x537.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/automated-browser-testing-1-300x157.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/automated-browser-testing-1-768x402.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/automated-browser-testing-1.png 1357w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><figcaption><em>Source:&nbsp;<a href=\"https:\/\/www.w3schools.com\/html\/html_tables.asp\" rel=\"noreferrer noopener\" target=\"_blank\">W3School<\/a><\/em><\/figcaption><\/figure>\n<\/div>\n<p>Though the header in a web table does not the <code>&lt; td &gt;<\/code>, the <code>&lt; th &gt;<\/code> tag could still be used in the current example to calculate the number of columns. The XPath for computing the number of columns using <code>&lt; th &gt;<\/code> tag is \/\/*[@id=\u2019customers\u2019]\/tbody\/tr\/th<\/p>\n<p>A WebDriverWait of 30 seconds is added to ensure that the loading of the Web Table (CLASS_NAME = w3-example) is complete before any operations are performed to handle the table in Selenium.<\/p>\n<p><strong>Get number of rows for a web table in Selenium<\/strong><\/p>\n<div>\n<div id=\"highlighter_164120\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">num_rows = len (driver.find_elements_by_xpath(<\/code><code class=\"java string\">\"\/\/*[@id='customers']\/tbody\/tr\"<\/code><code class=\"java plain\">))<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Get number of columns for a web table in Selenium<\/strong><\/p>\n<div>\n<div id=\"highlighter_160647\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">num_cols = len (driver.find_elements_by_xpath(<\/code><code class=\"java string\">\"\/\/*[@id='customers']\/tbody\/tr[2]\/td\"<\/code><code class=\"java plain\">))<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Complete Implementation<\/strong><\/p>\n<pre class=\"brush:py\">import unittest\nimport time\nfrom selenium import webdriver\nfrom selenium.webdriver.support.select import Select\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\n \ntest_url = \"https:\/\/www.w3schools.com\/html\/html_tables.asp\"\n \nclass WebTableTest(unittest.TestCase):\n \n    def setUp(self):\n        self.driver = webdriver.Chrome()\n        self.driver.maximize_window()\n \n    def test_1_get_num_rows_(self):\n        driver = self.driver\n        driver.get(test_url)\n        \n        WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CLASS_NAME, \"w3-example\")))\n \n        num_rows = len (driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr\"))\n        print(\"Rows in table are \" + repr(num_rows))\n \n    def test_2_get_num_cols_(self):\n        driver = self.driver\n        driver.get(test_url)\n        \n        WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CLASS_NAME, \"w3-example\")))\n        # num_cols = len (driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr\/th\"))\n        num_cols = len (driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr[2]\/td\"))\n        print(\"Columns in table are \" + repr(num_cols))\n \n    def tearDown(self):\n        self.driver.close()\n        self.driver.quit()\n \nif __name__ == \"__main__\":\n    unittest.main()\n<\/pre>\n<p>Below is the output snapshot<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"774\" height=\"173\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/selenium-webdriver.png\" alt=\"\" class=\"wp-image-106366\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/selenium-webdriver.png 774w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/selenium-webdriver-300x67.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/selenium-webdriver-768x172.png 768w\" sizes=\"(max-width: 774px) 100vw, 774px\" \/><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\">Print Content Of The Web Table In Selenium<\/h3>\n<p>To access the content present in every row and column to handle the table in Selenium, we iterate each and every row (<code>&lt; tr &gt;<\/code>) in the web table. Once the details about the rows are obtained, we iterate the <code>&lt; td &gt;<\/code> tags under that row.<\/p>\n<p>In this case for this Selenium WebDriver tutorial, both the rows (<code>&lt; tr &gt;<\/code>) and columns (<code>&lt; td &gt;<\/code>) would be variable. Hence, the row numbers and column numbers are computed dynamically. Shown below is the XPath for accessing information in specific rows and columns:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>XPath to access Row :<\/strong> 2, Column : 2 \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[2]\/td[1]<\/li>\n<li><strong>XPath to access Row :<\/strong> 3, Column : 1 \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[3]\/td[1]<\/li>\n<\/ul>\n<p>The table on which Selenium test automation is being performed has 7 rows and 3 columns. Hence, a nested for loop is executed with rows ranging from 2..7 and columns ranging from 1..4. The variables factors i.e. row number and column number are added to formulate the final XPath.<\/p>\n<div>\n<div id=\"highlighter_650863\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">for<\/code> <code class=\"java plain\">t_row in range(<\/code><code class=\"java value\">2<\/code><code class=\"java plain\">, (rows + <\/code><code class=\"java value\">1<\/code><code class=\"java plain\">)):<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;<\/code><code class=\"java keyword\">for<\/code> <code class=\"java plain\">t_column in range(<\/code><code class=\"java value\">1<\/code><code class=\"java plain\">, (columns + <\/code><code class=\"java value\">1<\/code><code class=\"java plain\">)):<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">FinalXPath = before_XPath + str(t_row) + aftertd_XPath + str(t_column) + aftertr_XPath<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">cell_text = driver.find_element_by_xpath(FinalXPath).text<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Shown below in this Selenium WebDriver tutorial, is the complete implementation to get all the contents present to handle table in Selenium.<\/p>\n<pre class=\"brush:py\">import unittest\nimport time\ntest_url = \"https:\/\/www.w3schools.com\/html\/html_tables.asp\"\n \nbefore_XPath = \"\/\/*[@id='customers']\/tbody\/tr[\"\naftertd_XPath = \"]\/td[\"\naftertr_XPath = \"]\"\n \n    def test_get_row_col_info_(self):\n        driver = self.driver\n        driver.get(test_url)\n        \n        # time.sleep(30)\n        WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CLASS_NAME, \"w3-example\")))\n \n        rows = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr\"))\n        # print (rows)\n        columns = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr[2]\/td\"))\n        # print(columns)\n        \n        # print(\"Company\"+\"               \"+\"Contact\"+\"               \"+\"Country\")\n \n        for t_row in range(2, (rows + 1)):\n            for t_column in range(1, (columns + 1)):\n                FinalXPath = before_XPath + str(t_row) + aftertd_XPath + str(t_column) + aftertr_XPath\n                cell_text = driver.find_element_by_xpath(FinalXPath).text\n                # print(cell_text, end = '               ')\n                print(cell_text)\n            print()   \n<\/pre>\n<p>The output snapshot to print content to handle table in Selenium is below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"512\" height=\"257\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/table-in-Selenium.png\" alt=\"\" class=\"wp-image-106367\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/table-in-Selenium.png 512w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/table-in-Selenium-300x151.png 300w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\">Read Data In Rows To Handle Table In Selenium<\/h3>\n<p>For accessing the content present in every row, to handle table in Selenium, the rows (<code>&lt; tr &gt;<\/code>) are variable whereas the columns (<code>&lt; td &gt;<\/code>) would remain constant. Hence, the rows are computed dynamically. Below in this Selenium WebDriver tutorial is the XPath for accessing information with rows being the variable factor and columns remaining constant for Selenium test automation.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>XPath to access Row :<\/strong> 1, Column : 1 \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[1]\/td[1]<\/li>\n<li><strong>XPath to access Row :<\/strong> 2, Column : 2 \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[2]\/td[2]<\/li>\n<li><strong>XPath to access Row :<\/strong> 3, Column : 2 \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[3]\/td[2]<\/li>\n<\/ul>\n<p>A for loop is executed with rows ranging from 2..7. The column values are appended to the XPath are td[1]\/td[2]\/td[3] depending on the row &amp; column that has to be accessed to handle the table in Selenium.<\/p>\n<div>\n<div id=\"highlighter_149490\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">before_XPath = <\/code><code class=\"java string\">\"\/\/*[@id='customers']\/tbody\/tr[\"<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java plain\">aftertd_XPath_1 = <\/code><code class=\"java string\">\"]\/td[1]\"<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java plain\">aftertd_XPath_2 = <\/code><code class=\"java string\">\"]\/td[2]\"<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java plain\">aftertd_XPath_3 = <\/code><code class=\"java string\">\"]\/td[3]\"<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">&nbsp;<\/code>&nbsp;<\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java keyword\">for<\/code> <code class=\"java plain\">t_row in range(<\/code><code class=\"java value\">2<\/code><code class=\"java plain\">, (rows + <\/code><code class=\"java value\">1<\/code><code class=\"java plain\">)):<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">FinalXPath = before_XPath + str(t_row) + aftertd_XPath_1<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">cell_text = driver.find_element_by_xpath(FinalXPath).text<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">print(cell_text)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Complete Implementation<\/strong><\/p>\n<pre class=\"brush:py\">#Selenium webdriver tutorial  to handletable in Selenium for Selenium test automation\nimport unittest\nimport time\nfrom selenium import webdriver\nfrom selenium.webdriver.support.select import Select\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\n \ntest_url = \"https:\/\/www.w3schools.com\/html\/html_tables.asp\"\n \nbefore_XPath = \"\/\/*[@id='customers']\/tbody\/tr[\"\naftertd_XPath_1 = \"]\/td[1]\"\naftertd_XPath_2 = \"]\/td[2]\"\naftertd_XPath_3 = \"]\/td[3]\"\n#aftertr_XPath = \"]\"\n \n    def test_get_row_col_info_(self):\n        driver = self.driver\n        driver.get(test_url)\n        \n        # time.sleep(30)\n        WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CLASS_NAME, \"w3-example\")))\n \n        rows = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr\"))\n        # print (rows)\n        columns = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr[2]\/td\"))\n        # print(columns)\n \n        print(\"Data present in Rows, Col - 1\")\n        print()\n        for t_row in range(2, (rows + 1)):\n            FinalXPath = before_XPath + str(t_row) + aftertd_XPath_1\n            cell_text = driver.find_element_by_xpath(FinalXPath).text\n            print(cell_text)\n        \n        print()    \n        print(\"Data present in Rows, Col - 2\")\n        print()\n        for t_row in range(2, (rows + 1)):\n            FinalXPath = before_XPath + str(t_row) + aftertd_XPath_2\n            cell_text = driver.find_element_by_xpath(FinalXPath).text\n            print(cell_text)\n            \n        print()\n        print(\"Data present in Rows, Col - 3\")\n        print()\n        for t_row in range(2, (rows + 1)):\n            FinalXPath = before_XPath + str(t_row) + aftertd_XPath_3\n            cell_text = driver.find_element_by_xpath(FinalXPath).text\n            print(cell_text) \n<\/pre>\n<p>The output snapshot to read data in rows to handle table in Selenium is below:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/handle-table-in-Selenium.png\" alt=\"\" class=\"wp-image-106368\" width=\"624\" height=\"398\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/handle-table-in-Selenium.png 832w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/handle-table-in-Selenium-300x191.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/handle-table-in-Selenium-768x489.png 768w\" sizes=\"(max-width: 624px) 100vw, 624px\" \/><\/figure>\n<\/div>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/www.lambdatest.com\/lt-browser\"><img decoding=\"async\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/LT-Browser-1.jpg\" alt=\"\" class=\"wp-image-106370\" width=\"698\" height=\"135\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/LT-Browser-1.jpg 930w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/LT-Browser-1-300x58.jpg 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/LT-Browser-1-768x149.jpg 768w\" sizes=\"(max-width: 698px) 100vw, 698px\" \/><\/a><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\">Read Data In Columns To Handle Table In Selenium<\/h3>\n<p>For column-wise access to handle table in Selenium, the rows remain constant whereas the column numbers are variable i.e. the columns are computed dynamically. Below in this Selenium WebDriver Tutorial is the XPath for accessing information where columns are variable and rows are constant.<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>XPath to access Row : 2, Column : 2<\/strong> \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[2]\/td[2]<\/li>\n<li><strong>XPath to access Row : 2, Column : 3<\/strong> \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[2]\/td[3]<\/li>\n<li><strong>XPath to access Row : 2, Column : 4<\/strong> \u2013 \/\/*[@id=\u201dcustomers\u201d]\/tbody\/tr[2]\/td[4]<\/li>\n<\/ul>\n<p>A for loop is executed with columns ranging from 1..4 The row values are appended to the XPath are tr[1]\/tr[2]\/tr[3] depending on the row &amp; column that has to be accessed.<\/p>\n<div>\n<div id=\"highlighter_385456\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java plain\">before_XPath_1 = <\/code><code class=\"java string\">\"\/\/*[@id='customers']\/tbody\/tr[1]\/th[\"<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java plain\">before_XPath_2 = <\/code><code class=\"java string\">\"\/\/*[@id='customers']\/tbody\/tr[2]\/td[\"<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java plain\">after_XPath = <\/code><code class=\"java string\">\"]\"<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;<\/code>&nbsp;<\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java keyword\">for<\/code> <code class=\"java plain\">t_col in range(<\/code><code class=\"java value\">1<\/code><code class=\"java plain\">, (num_columns + <\/code><code class=\"java value\">1<\/code><code class=\"java plain\">)):<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">FinalXPath = before_XPath_1 + str(t_col) + after_XPath<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">cell_text = driver.find_element_by_xpath(FinalXPath).text<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">print(cell_text)<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Complete Implementation<\/strong><\/p>\n<pre class=\"brush:py\">import unittest\nimport time\nfrom selenium import webdriver\nfrom selenium.webdriver.support.select import Select\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\n \ntest_url = \"https:\/\/www.w3schools.com\/html\/html_tables.asp\"\n \nbefore_XPath_1 = \"\/\/*[@id='customers']\/tbody\/tr[1]\/th[\"\nbefore_XPath_2 = \"\/\/*[@id='customers']\/tbody\/tr[2]\/td[\"\nafter_XPath = \"]\" \n \ndef test_get_row_col_info_(self):\n        driver = self.driver\n        driver.get(test_url)\n        \n        # time.sleep(30)\n        WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CLASS_NAME, \"w3-example\")))\n \n        num_rows = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr\"))\n        # print (rows)\n        num_columns = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr[2]\/td\"))\n        # print(columns)\n \n        print(\"Data present in Col - 1 i.e. Title\")\n        print()\n        for t_col in range(1, (num_columns + 1)):\n            FinalXPath = before_XPath_1 + str(t_col) + after_XPath\n            cell_text = driver.find_element_by_xpath(FinalXPath).text\n            print(cell_text)\n            \n        print(\"Data present in Col - 2\")\n        print()\n        for t_col in range(1, (num_columns + 1)):\n            FinalXPath = before_XPath_2 + str(t_col) + after_XPath\n            cell_text = driver.find_element_by_xpath(FinalXPath).text\n            print(cell_text)\n<\/pre>\n<p>As seen in the execution snapshot, the header column is also read to fetch the title of the columns.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><img decoding=\"async\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/image6-6-1024x266.png\" alt=\"\" class=\"wp-image-106371\" width=\"768\" height=\"200\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/image6-6-1024x266.png 1024w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/image6-6-300x78.png 300w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/image6-6-768x200.png 768w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/image6-6.png 1093w\" sizes=\"(max-width: 768px) 100vw, 768px\" \/><\/figure>\n<\/div>\n<h3 class=\"wp-block-heading\">Locating An Element To Handle Table In Selenium<\/h3>\n<p>The intention of this test for this Selenium WebDriver tutorial is to look for the presence of an element in the web table. For doing the same, content in each and every cell of the web table is read and compared with the search term. If the element is present, the corresponding row and element are printed to handle the table in Selenium.<\/p>\n<p>As it involves reading the data in every cell, we make use of the logic covered in the section titled Print content of the web table in Selenium. A case insensitive search is performed to validate the presence of the search term to handle table in Selenium.<\/p>\n<div>\n<div id=\"highlighter_686804\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">for<\/code> <code class=\"java plain\">t_row in range(<\/code><code class=\"java value\">2<\/code><code class=\"java plain\">, (num_rows + <\/code><code class=\"java value\">1<\/code><code class=\"java plain\">)):<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;<\/code><code class=\"java keyword\">for<\/code> <code class=\"java plain\">t_column in range(<\/code><code class=\"java value\">1<\/code><code class=\"java plain\">, (num_columns + <\/code><code class=\"java value\">1<\/code><code class=\"java plain\">)):<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">FinalXPath = before_XPath + str(t_row) + aftertd_XPath + str(t_column) + aftertr_XPath<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">cell_text = driver.find_element_by_xpath(FinalXPath).text<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">if<\/code> <code class=\"java plain\">((cell_text.casefold()) == (search_text.casefold())):<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">print(<\/code><code class=\"java string\">\"Search Text \"<\/code><code class=\"java plain\">+ search_text +<\/code><code class=\"java string\">\" is present at row \"<\/code> <code class=\"java plain\">+ str(t_row) + <\/code><code class=\"java string\">\" and column \"<\/code> <code class=\"java plain\">+ str(t_column))<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java plain\">elem_found = True<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<\/code><code class=\"java keyword\">break<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p><strong>Complete Implementation<\/strong><\/p>\n<pre class=\"brush:py\">import unittest\nimport time\nfrom selenium import webdriver\nfrom selenium.webdriver.support.select import Select\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.support.ui import WebDriverWait\nfrom selenium.webdriver.support import expected_conditions as EC\n \ntest_url = \"https:\/\/www.w3schools.com\/html\/html_tables.asp\"\n \nbefore_XPath_1 = \"\/\/*[@id='customers']\/tbody\/tr[1]\/th[\"\nbefore_XPath_2 = \"\/\/*[@id='customers']\/tbody\/tr[2]\/td[\"\nafter_XPath = \"]\"\n \nsearch_text = \"mAgazzini Alimentari rIUniti\"\n \n    def test_get_row_col_info_(self):\n        driver = self.driver\n        driver.get(test_url)\n        \n        # time.sleep(30)\n        WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.CLASS_NAME, \"w3-example\")))\n \n        num_rows = len(driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr\"))\n        num_columns = len (driver.find_elements_by_xpath(\"\/\/*[@id='customers']\/tbody\/tr[2]\/td\"))\n        \n        elem_found = False\n \n        for t_row in range(2, (num_rows + 1)):\n            for t_column in range(1, (num_columns + 1)):\n                FinalXPath = before_XPath + str(t_row) + aftertd_XPath + str(t_column) + aftertr_XPath\n                cell_text = driver.find_element_by_xpath(FinalXPath).text\n                if ((cell_text.casefold()) == (search_text.casefold())):\n                    print(\"Search Text \"+ search_text +\" is present at row \" + str(t_row) + \" and column \" + str(t_column))\n                    elem_found = True\n                    break\n        if (elem_found == False):\n            print(\"Search Text \"+ search_text +\" not found\")\n<\/pre>\n<p>As seen in the execution snapshot for this Selenium WebDriver tutorial, the search term was present at row-7 and column-1<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><img decoding=\"async\" width=\"603\" height=\"139\" src=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Selenium-WebDriver-tutorial.png\" alt=\"\" class=\"wp-image-106372\" srcset=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Selenium-WebDriver-tutorial.png 603w, https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2020\/08\/Selenium-WebDriver-tutorial-300x69.png 300w\" sizes=\"(max-width: 603px) 100vw, 603px\" \/><\/figure>\n<\/div>\n<p>Though there are many such operations can be carried out on web table in Selenium, we have covered the core aspects in this Selenium WebDriver tutorial.<\/p>\n<p><a href=\"https:\/\/www.lambdatest.com\/blog\/how-to-automate-calendar-using-selenium-webdriver-for-testing\/\" target=\"_blank\" rel=\"noopener noreferrer\">Read More: How To Automate Calendar In Selenium WebDriver For Automation Testing?<\/a><\/p>\n<h2 class=\"wp-block-heading\">All In All<\/h2>\n<p>Web tables are commonly used when information has to be displayed in tabular format. The information in the cells can be static or dynamic. Web tables in Selenium are tested using WebElement APIs along with usage of appropriate locators like XPath, CSS class name, CSS ID, etc.<\/p>\n<p>I hope you liked this Selenium WebDriver tutorial to handle the table in Selenium. Do leave your thoughts on using web tables in Selenium test automation in the comments section down below. Feel free to share it with your peers. Till then. <strong>Happy Testing!!!<\/strong>\ud83d\ude0a<\/p>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Himanshu Sheth, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener noreferrer\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/www.lambdatest.com\/blog\/how-to-handle-web-table-in-selenium-webdriver\/\" target=\"_blank\" rel=\"noopener noreferrer\">How To Handle Web Table in Selenium WebDriver?<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either be static or dynamic in nature. You\u2019d often see such examples in e-commerce portals, where product specifications are displayed in a web table. With its wide use, you\u2019d &hellip;<\/p>\n","protected":false},"author":81931,"featured_media":231,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[1321,287,286],"class_list":["post-106339","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-automation","tag-selenium","tag-webdriver"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How To Handle Web Table in Selenium WebDriver? - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How To Handle Web Table in Selenium WebDriver? - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2020-08-18T07:00:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/selenium-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Himanshu Sheth\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Himanshu Sheth\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"14 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html\"},\"author\":{\"name\":\"Himanshu Sheth\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/a25d993a76017c1c681bf9ca6e6ad8ad\"},\"headline\":\"How To Handle Web Table in Selenium WebDriver?\",\"datePublished\":\"2020-08-18T07:00:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html\"},\"wordCount\":1581,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/selenium-logo.jpg\",\"keywords\":[\"Automation\",\"Selenium\",\"WebDriver\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html\",\"name\":\"How To Handle Web Table in Selenium WebDriver? - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/selenium-logo.jpg\",\"datePublished\":\"2020-08-18T07:00:00+00:00\",\"description\":\"Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/selenium-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/selenium-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2020\\\/08\\\/how-to-handle-web-table-in-selenium-webdriver.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"How To Handle Web Table in Selenium WebDriver?\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/a25d993a76017c1c681bf9ca6e6ad8ad\",\"name\":\"Himanshu Sheth\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g\",\"caption\":\"Himanshu Sheth\"},\"description\":\"Himanshu Seth is an engineer with 15+ years of experience. He has worked with multi-national companies as well as startups. He is also an avid blogger on technology.\",\"sameAs\":[\"https:\\\/\\\/www.lambdatest.com\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/himanshu-sheth\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How To Handle Web Table in Selenium WebDriver? - Java Code Geeks","description":"Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html","og_locale":"en_US","og_type":"article","og_title":"How To Handle Web Table in Selenium WebDriver? - Java Code Geeks","og_description":"Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either","og_url":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2020-08-18T07:00:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/selenium-logo.jpg","type":"image\/jpeg"}],"author":"Himanshu Sheth","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Himanshu Sheth","Est. reading time":"14 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html"},"author":{"name":"Himanshu Sheth","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/a25d993a76017c1c681bf9ca6e6ad8ad"},"headline":"How To Handle Web Table in Selenium WebDriver?","datePublished":"2020-08-18T07:00:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html"},"wordCount":1581,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/selenium-logo.jpg","keywords":["Automation","Selenium","WebDriver"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html","url":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html","name":"How To Handle Web Table in Selenium WebDriver? - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/selenium-logo.jpg","datePublished":"2020-08-18T07:00:00+00:00","description":"Web tables or data tables are often used in scenarios where you need to display the information in a tabular format. The data being displayed can either","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/selenium-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/selenium-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2020\/08\/how-to-handle-web-table-in-selenium-webdriver.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"How To Handle Web Table in Selenium WebDriver?"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/a25d993a76017c1c681bf9ca6e6ad8ad","name":"Himanshu Sheth","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/8a190453d43aa252452a7c12c73f8d396bbe3c7428c79482d046eb611ad1929f?s=96&d=mm&r=g","caption":"Himanshu Sheth"},"description":"Himanshu Seth is an engineer with 15+ years of experience. He has worked with multi-national companies as well as startups. He is also an avid blogger on technology.","sameAs":["https:\/\/www.lambdatest.com"],"url":"https:\/\/www.javacodegeeks.com\/author\/himanshu-sheth"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/106339","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/81931"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=106339"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/106339\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/231"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=106339"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=106339"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=106339"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}