{"id":2741,"date":"2023-11-19T16:26:01","date_gmt":"2023-11-19T16:26:01","guid":{"rendered":"https:\/\/rahulshettyacademy.com\/blog\/?p=2741"},"modified":"2023-12-03T06:54:26","modified_gmt":"2023-12-03T06:54:26","slug":"handle-webtables-in-selenium-webdriver","status":"publish","type":"post","link":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/2023\/11\/19\/handle-webtables-in-selenium-webdriver\/","title":{"rendered":"Handle WebTables in Selenium Webdriver"},"content":{"rendered":"\n<p>Navigate to <a href=\"https:\/\/money.rediff.com\/index.html\" target=\"_blank\" rel=\"noopener\">https:\/\/money.rediff.com\/index.html<\/a><\/p>\n\n\n\n<p>Click \u2018More gainers\u2019 link that you see in below figure<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/TrfdDn04saEbslsahGXnRRKukJYRrawA9UPn-qX00z4MPkBnh5TDtIiYwoKU_2onerjaft500k9DzGVFCxYFaJc8Ap06EMST7MIoITyon8l0UdGd2F5xAQNqeeU4hw1enFjda3BdFWN3froCp4jDWXS8uNqpLR7NvG3-8RytYQji1P42DolCS9QgAWVX3PY\" width=\"662\" height=\"238\"><br>You get a list of all the companies, see below figure<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/m13lpU29Tk8A4I76fXPh1QCpNCJICxcZUAtZcBDFKTe1A38jf-Jt0wcAD5SKoK2x0IyzljA2PHRz1TqKfYAxmw7rN_9GHb6BkTKxf_x8bLzTklj9CeGRrqEKi6NK4Lkn5ocMeugSMBfHviq8x9mU-5KzgJAtC_V7B0M29DZ0bZIkN2M8ETf93-aQ4O92tNE\" alt=\"\"\/><\/figure>\n\n\n\n<p>This is an example of Webtable, it is a kind of an excel file where elements are present in a systematic tabular manner.<\/p>\n\n\n\n<p>Right click &amp; inspect this Webtable, you will see that this webtable is under \u2018<em>&lt;table&gt;<\/em>\u2019 tag<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/CjI9ZRGJjJJepgIk_7zecQNh8eko-kd8dIQYCuwpBmpP3jTRCD7uogou2gbbdyTguWZTcQwwPM1VFwahqbShWieiLyxfHJg7C9biLOlNwtvuTUacSnmJgnWf9uePhbeUlTMc8Q0fy5c035j5avgpr0j_vRnGGld4CgbM0zwuwMbpJD5zQWWNAs2p9crErh4\" alt=\"\"\/><\/figure>\n\n\n\n<p>If you hover over &lt;<strong>table<\/strong> <strong>class=\u201ddataTable\u201d&gt;<\/strong>, the entire Webtable is highlighted<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/ugapmEeoiOyAAgmmMheMBH2pOcKehFLj4TqncVNYecbxAp1PJTjUIaa095mjVz7V18jsCl8GD-gfy6HwuTgQs4zz98UxIPZFHcharhhuWkwRqw6BzXaSDdwtOtiyb84Rcjoo2Iw_Nx9pdlhd3Tvupin9uu5RiLO08GU0GsmsSkZ-wiM6oN7Fuqwbm6uE5UI\" alt=\"\"\/><\/figure>\n\n\n\n<p>So, <strong><em>table<\/em><\/strong> is the parent tag of all the webtables<\/p>\n\n\n\n<p>Inside the &lt;table&gt; tag we have 2 immediate child tags as shown below: <strong><em>thead<\/em><\/strong> and <strong><em>tbody<\/em><\/strong>&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/YB4M3Sxy7NpgL7BiuykxtOEmKmf7BjmQv6Y7O-4t08mfcAQ-VFFrBwN2Cra50JJrfnykDZWecAVrtBhEejw2VQjHsnP8yqnkM5cUCJMZeRmgSZlUAb2qZ0Es94nM_z5ng7M9ixpwMo0ddJfGBByUPoxf-NhMdbiITCCU2uEs6QXjxKD5_GxlUsyhelyocng\" alt=\"\"\/><\/figure>\n\n\n\n<p>When we expand the <strong>thead<\/strong> tag, we can see that it contains the <strong><em>tr<\/em><\/strong><strong> <\/strong>tag (<strong><em>r<\/em><\/strong><strong> <\/strong>stands for<strong> <\/strong><strong><em>row<\/em><\/strong><strong>)<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/bMkm62xvbbja4AtTGwtR9K4OVaKwcaOEskQqSNAp2FhbvAvb3xkG-Vjamc1jT0GOYbaxfitTBOSZfNnkhjn5jYoGKnxKgGcIzYO8xJ2GST3H4BhykxYdyJ1EqiLgKlxYbISGUSEgNBpVaXe7H1WOBpXneHzxl4bws2qBK-2lDTRogPaCL7bxoWNT58kGVXo\" alt=\"\"\/><\/figure>\n\n\n\n<p>When we mouse hover over <strong>tr<\/strong>, we would see entire first row getting highlighted, see below&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/_l56ZfcFAyoyR-FR3hP-ow-4B2SsuYZBzLVObTBStsG56G5hwKiz9HpLtmFTlYgQNEn2ty4tEzaxrXgU3CGsTFKsiB4QA-qso6-BqXVdlFzuz7w3AGX8yiTaEZG2V-AyAcdPRQjcy1UW4dpv4XnWRCiyP28ylC30AtB2wqR48Lm5L7y6-V5s9zF2dAtHmds\" alt=\"\"\/><\/figure>\n\n\n\n<p>Expand &lt;<strong>tr&gt; <\/strong>tag, it contains &lt;<strong>th&gt; <\/strong>tags (<strong>th <\/strong>for <strong>table headings<\/strong>)<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/2HyS3nSuWkcibIECo_a6GmCoVUyHj1aZVBKVFBlAMApTKqt41ljn2yIzh-ZQEmPyx--cDcjpMOoxkb4auFvOrh_yry8zI4mqbaHjq0t2TP5r3kvecgZjEUUIOcl_OrDcr3eLPRWGXTcyy31MnEYLVzldbWLv80tE1MVBHzLoTdvuqXhwjiHg9lic0IQZmng\" alt=\"\"\/><\/figure>\n\n\n\n<p>When we mouse hover over any &lt;th&gt; tag, the respective table heading gets highlighted.&nbsp;<\/p>\n\n\n\n<p>For example, mouse hover <em>&lt;th&gt;Current Price (Rs)&lt;\/th&gt;<\/em>, notice that \u2018<em>Current Price (Rs)<\/em>\u2019 column name gets highlighted<br><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/TUuf7hnB_smavxo_INM2dPnyEnKV2Ru-U0RZWghGKKabt5b-JFTaxcDvipI1jM3Zn0pFE-Mz086VDX1_6Yc8bN-_kTH82Qk_Uo53V-YDCiQG9L4B6ysXB-gZjGv3GFRqrKA28hSZ7CJCbcmdwaJn-Zgdr8trR66bU9nXI3zgoLicSVjaowxhkPMOEOwrjWc\" width=\"670\" height=\"483\"><br><\/p>\n\n\n\n<p>Similarly you can mouse hover other &lt;th&gt; tags.<\/p>\n\n\n\n<p>Now let us expand &lt;<strong>tbody&gt;<\/strong> tag. It contains various <strong>tr <\/strong>tags corresponding to each row. So each <strong>tr<\/strong> tag represents table row. So if you mouse hover any <strong>tr<\/strong> tag, you see the respective company row getting highlighted, see below<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/y7VxsxAlJijYbP-RI7sZ_CDrOToxoqYI3G60Ug6A-bB22bPHTE3xTuOKM2gnFSlj53h4tKPt70JjVYc4NzhSUnhni3N6pirLWATgJuFmH7PKKn1g15tRJwVAeN8bzKGrPHGM5D0Mk9gGZcmR--dMdQuxu_GIOtnf5KLkTn2BeSPqC-V-AagY1kN3ifiahFw\" alt=\"\"\/><\/figure>\n\n\n\n<p>Let us expand &lt;<strong>tr<\/strong>&gt; tag. It contains <strong>td <\/strong>tag that holds the data of a particular cell. So if you mouse hover over &lt;td&gt;18.88&lt;\/td&gt;, you see that 18.88 getting highlighted<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/QL5BMZ4X_8uYSwOWZg75GkuKnoF0rw9wlllNmgJ7zmkAGbHFWUQUUJc_cmZubS13MFnv6W5ohu51ytarHcFnddjo_rPvnA_rUAeu1GgJTK0_Lujafi1OJ1FNju5S0d4CKsZD1FF80qDh6ylj6zxssC-CVFMBQXWHIvhG5cn9wN6IL_5W1C3Sb55PpxyY6mI\" alt=\"\"\/><\/figure>\n\n\n\n<p>Webtable hierarchy can thus be represented as below:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/eYwoK3KjCFgYJ7dUyt-RcAzBzAHuA7TKJYwpNzYC-jS_EZeDe1loUaG8uMMpMof3vv22cvY2SNfHtlNGOk-kUizB8Ap3kRp1Ux-4Ecqqu2UbIHGHZaWdolp1pqtA__0qjtgjAVAYh0uh7ErVtauvhgI0cbbw_aLyRVRhadZh8cn2a9IpOpxGzuXPr9mWiOs\" alt=\"\"\/><\/figure>\n\n\n\n<p>Let us try to create few custom xpaths for the webtable.<\/p>\n\n\n\n<p>We earlier saw that the <strong>table <\/strong>tag has \u201c<strong>class\u201d <\/strong>attribute having the value \u2018<strong>dataTable<\/strong>\u2019<br><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/CjI9ZRGJjJJepgIk_7zecQNh8eko-kd8dIQYCuwpBmpP3jTRCD7uogou2gbbdyTguWZTcQwwPM1VFwahqbShWieiLyxfHJg7C9biLOlNwtvuTUacSnmJgnWf9uePhbeUlTMc8Q0fy5c035j5avgpr0j_vRnGGld4CgbM0zwuwMbpJD5zQWWNAs2p9crErh4\" width=\"663\" height=\"312\"><\/p>\n\n\n\n<p>Execute the below custom xpath in SelectorsHub<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/PfaE1fX4nrIZXktCyR1UNkyvHMSQ5C0DEOWCW3rht4wNLFHz9dy1p2scNA1iNT_Yk8IOfkye4REpsrcsj6uzoTe6Yv94radhzwc3TFg7UWvOdJnutUrjU5HqbeNmYg1o23-ahsurpbcUDOM4LGycoCNc6MeyFlKlQ7dy9CPfkDphk7j_M7V-VfUdRn5mTKo\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/Vb7VQgyLx5lXyFtB6fWeH_ZZyN6ML0uWQfQyYElKORrhfYS7DN2Ro0Xb6CvWkT0wMUEADt791647HENXLCtdG2BSfLi5VwuaGEZH6g-5Hl_6ngOjZZRwrFGegsO-ETH3kZckpM23XoCCUS0kvePaW2OOMtYpiuHBThkW-NBsfJtPIn6rEmQT03XEwxnD3mA\" alt=\"\"\/><\/figure>\n\n\n\n<p>This will select the entire webtable as shown below<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/uYYKHDh_g9oDNahrIKyXq_DRpQbCdw6o_ZRRJYveLdF80FakQ6SbVEdxdDkFnolByZNXs9gNyLYLYkobc3QQ_ZrZ6RbAClOqEREio0n9pYawnCHJMTdEiZji-4XdX4ahRvhh3IvrixgBgMoT2ST120-qN9m07CNu3lAYe3blcE2ZjmNIxHEWot83CZk-wcY\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/tfft3pNgRHPG_JGYDUQXiDTTSSHA5BkbvmHQfBpjI6fG0f2-ZBhLVkOce9KJ4J9L0r1Wsm-SaxJ0KdlyXGJP88g9Gd1O9r6pR2oL1nUmIE3otfaU95wKRQeXo8ECl4R2nqCOJCToB21vdbMVMFtUjWLHoUkGpkGH4GvezECMEPvaFImbkKJheav_MH7m41w\" alt=\"\"\/><\/figure>\n\n\n\n<p>Let us now extend this custom xpath by appending <strong>tbody<\/strong> tag that in turn contains <strong>tr<\/strong> tag that in turn contains <strong>td<\/strong> tag<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/La_kK4alM4Y28-fLVfeMEy7wJi8efMDi0A3T64zCsd4lgoWxTmHqLVzjHK-NMyqucPSaej2KUVFSb5LFMDn3szqWDc0ki9pNkuK9zrbVJiMXSWMR1SlQIBiRUZd2pb4KL6lJUh2qwRJ8kgtopv68fOf39pQ7LXyTow0Bj343afejdg4hMsd-54pNJB1HqPs\" width=\"628\" height=\"49\"><br>See that all the rows and columns get highlighted<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/le1X_Hr2MlJYL1bLkDpDoCop0FCBR1pj0NBQaJx0z-js8SPWNrFOUhQ7vsLcNTDyzW0sBCDZpTYOSlOOOl34T1yHO0QC8AKXkSKKhznFZQzXJz59sfT4LOz9wZBkRy3GYO82FrHkF2aq_mH0YXR_y6qo0LAQY95_e6lgN9gCAq4gU7f1ntCTQ6-uAwLkuy4\" alt=\"\"\/><\/figure>\n\n\n\n<p>Below xpath would highlight 5<sup>th<\/sup> cell data of 4th row&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/WE8Un_bQADIP73831qyOoHD0n3miuLx6JeHB1EPOxSeDP1FHit0oMN0Spcw-yEE5r9FCUC_NNT_f19qhlpJnWkMhRfqzakwU3tnEHyxYB5NKhRHOh5fCPJOstvFm1uFx5RNKUAaRUspJXHzg3WnnZMOeGeJ_3D-3RXinogeohZch1CmXx3JUY1WxwjcibqI\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/VYgOok3Jz_eqm7NbEUIJBnS0G9lMymKJlpNPcD3YhNnZKLdyuK3G3XhD8XQc3NRlv45xtuTepKAVTZzkBmuf8LEIlLQ4ZSzQ11PgkdLDCzqgI0EcpH6fJk4Algd0md5TmdOxian1N6eTzipnC7Oc2-UQxXsOZlgoGbw_r8Sm_ruszdr7shZPaKexe9fd7vU\" alt=\"\"\/><\/figure>\n\n\n\n<p>Below xpath would highlight entire 4th row<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/NhNfMJe4cSjmut9cN1uMpRobLtYNbE7stnweqiJJKsrb8ihMO5Q_LubUgmgdLIvYbVZcuJTWW3ikXipc157AKo-2LVz1xz6u86HZV7QmCyERaqI02XzrZ3Nw8MpaLvP3-_kjacsU1h2tilfm4menig3tqntRkZLEis5GBeYFbhJjSarJw9S5GeswSs3lRi0\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/p0pz8V3Z7Az9lqzfouZiKFeK-Qdh53hpG8lk2kCnGKTSPooiVjXLG2N9qilABqhThPhgtYTV09Jn3TbPPiuCsy7RKPaLMIwQkFkR9EmQ1BOxbtzG7_b1iqTBop_RTdPui2G9I7pHnmNNtK0Lq7OVYffsYBbdxA03hXfYw3KFXl2yvtOeRV3ddjvIieYp-TM\" alt=\"\"\/><\/figure>\n\n\n\n<p>Below xpath would highlight all the individual cells of 4th row<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/4XalxcLr2TvEk490sBnXd3I1BonqFG8_aiSDxCegvzNcgvXGwITe55xvmhB_svkvTwhLp1YNTPB_RJ7CvuvgTMlpVWF_VRCoiKJXpxgYIgyYHjaN7pHrQWMfVy9e3ZuRzpDvJYpIv1hOVO5glZo-zL9PiZnRoAKqU0LGV7W981cjll883Ap1_XiSZUg4XMU\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/kFEI6HUO8rUBjWUYnnhCqxE8iujHoIDui52QvMshFV-oDo6uDd0FfezNudy746lzJoXg3PMKogqnjrHfs4Z7-ZlADmsEXXddB_7JL6au-8dHnPhApQkXEXaQL7e-uatzJKxt1etQz4RSrJvIkbtIbHpg4lFHIsnNqi2UMKLAlA8_HJ3kpKsYx5U7zyzt47k\" alt=\"\"\/><\/figure>\n\n\n\n<p>Below xpath represents all the rows<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/sHsXh_xZ00FyNvA9OwkwjT7f-RARSPVzlrHyAOV52HObabF6_aGsaaFycj9Oy773dzls2RvzZSWAIwVqIql0OMHYF5vXLLKEB0OBqemUt69SGPYjgkL_jlBUQ4KjEmUXq3UXqo0BUBVlcix6RujAsI9av0QOBiM7YnoOBqriah5KeyLnwy2tV1C0qcxiADI\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/UcseoHw3P9e4SF05IhNWQQ1LK5omoNXQ1cIfXk6mU-tjTxkSELY5pfx8jw2EXLGiDCnok5UQOwazJrx52sa6UiBVy10lATTgQJzyF2OPCw3vT4iIipGOA4r8WU0OqX7Lnj6e-sp3V4td8Xe5oPZR7QcPd7qj0CqhIZv_74CTH-2FuqzGoZ13XJAuiIkntMs\" alt=\"\"\/><\/figure>\n\n\n\n<p>Let us say we want to print the \u2018Current price\u2019 of \u2018<em>JK Lakshmi Cement L<\/em>\u2019<br><strong><em><br><\/em><\/strong><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/zOnwgkLYMt3Q6Fc6ynj8kYQqsyW72eNj23dv1U-AOhzmD72SWBZP9q_1kOuUe0LX2dP_x56lpqMBfume5XiodtoOF39J4uFP0dndkuX-nsh5nkEHsHYCPecOyq8vvn2xtZo3I3QfdPRJJD-K5e0adO35sr7F-FuiXUZt_dwl6r1b5nDRe7nuJ_0yrxRQp6I\" width=\"602\" height=\"69\"><strong><em><br><\/em><\/strong><br>Let us copy the text \u2018<em>JK Lakshmi Cement L<\/em>\u2019 from website page and create new class. Paste the company name in a string variable<br><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/SavbaN1oXeMn2Q_io-ZeDAyQ_rYIbPU33zYu_qafsgZhLyaLSGwh1_mYAy5nTtAnjMgibVTBozV_FFWknRbUFA4fdm58W1gNURarzOSRFc5QODYBXSRWZenXjzSzQEjO_btkavcjXfC82GfwOciS-7S6Ha9fmywz_22AroyuZJ69qwTLX22RML9FwzAViOg\" width=\"665\" height=\"168\"><br><br>Xpath of entire first column (company names) would be:&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/hQrLg-ydH9MiStRy7aNOlZX4LeJUYe9rEzCBCFjuQ8wnenXSFxTaPxLdwp5KXT6LBbZv_zW0tMeo-Ypxt6Q4vjasT7qTRo33ZgyN-wlTxGM3R-HiWpm9sHCZRy0wY9TwNTbBZx6MRk6HwTQPSVlTu49yfvQ8RhzOoLALwp9NRyYlKyuYKwl3PpYRVQiVvhk\" alt=\"\"\/><\/figure>\n\n\n\n<p><strong><br><\/strong>This will give us a list of all the companies<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/jIWd2hcWOqPeRoTm65C45_eoTGPPoYy8ifKH2GVPbCkGr7DsXLnvzTJLuGGXXES0LHOfkJX704VQhOqQ2eMawzLG6oaccTi-cdb6dgL_ggUMekDvm5AndLsA00rmoDC2_eFyYqfL5ics4m5KrSM9HyAhz9I408Fdc_em6MFgMm--xxlnx45qBV77-82n2xk\" alt=\"\"\/><\/figure>\n\n\n\n<p>Now we will extract all the values of first column (since first column gives us company name) using \u201c<em>findElement<\/em><strong><em>s<\/em><\/strong>\u201d<strong> <\/strong>method that returns us a \u2018List\u2019 (we have to import java.util.List)<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/mbWjIgel0IJTJXJ8sVUgJwD1QfS6cAiDsYOPVXAfuih_WktjhVN1T1ZjqCLsC-HIQnrSMzgLgRsGgGQmGy0DiXqAfNwARpkZGJvdZ44WkLuo_ucfguwNHnib9Rj9X_o7k0aAgjULmy4eqXnaK0r0_W0xedWPy6lrmLdW5hPG5TRny0bI6xgDz92y-aqk7vs\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/n9CAX-HSwHd_4ptr_SB_YmYtW2CDVEiODtgxQCTdgdam4copuOCu74gbav1Of_0fNsWue239ZCrfUp60zlxWpBsRG7jyNNhkWaRP_a5iQIZdrTh2rP7deLIviquQfKkJr2BNGWECGn_56KJuJcQDilRbaRvABkAHOPonO3Cn7Y3A_fXvMp0yNkwPpwt92e4\" alt=\"\"\/><\/figure>\n\n\n\n<p>Let us use a \u2018for\u2019 loop to print all the values (company names)&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/5k5D3FOpXaGhTLKjn0qfcJV9vVEgiaZmcsQTQZSSTX_4hWag6gXhPR4B9KFF9wXQL8TP22IPQ4tD-mG4VFz5VN-aWvQAzCawKkBXC-tA8Qnt740CzIWRyppSuVYlltpNqti3JBnCS5OFg6EE_PfCkhzQjI89WpWS-I0ilW3l_m4SQiOyVvg6Jjeoga-qYFM\" alt=\"\"\/><\/figure>\n\n\n\n<p>Run script, all the company names are printed<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/KPzpMGkQ373PfenzYspo3MJzuW6R4s_frnvcmuEzTY8JeQMFAFqRC2IkBY4NwxgLcPHU8S8Un8zcE9-HOJv0pBhxKVNhLLTGhC36_eUbpyrUvveGsxqc-HX9IkzUaSbq9VreqQ3ZsK-bq77P9RaDcZPUzf4F9yfOVvhNfyWRENBx9X7D_YOtkCBkPmHFcZk\" alt=\"\"\/><\/figure>\n\n\n\n<p><br>Similarly the xpath <strong>\/\/table[@class=&#8217;dataTable&#8217;]\/tbody\/tr\/td[4]<\/strong> will extract all the current prices (since column 4 gives us current price)<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/j9FItZPIDbYcTxgI3ppJ1rjMJS880W_p7uPASYcu8bEXm0y3hOvH6cFdHB5F7TR2ESp7puJME40koWKq26zChzrcXxfhRHDyckRIr9jXmM7EwlR3tj0bwjVks64DNEFRSIt29S4w2MmURgKNBSi8qMgZKTlYozdYXDnBbB3uDNnGPCuta5QlCfaAYkkioxE\" width=\"216\" height=\"240\"><br>So we can write<br><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/wBsI4ltJM-PHPuu3Ee0aSrgsjj7QKUBugpmssl9-pa1lACmLE29DbATk47S4eNIvSEaJkIxDqykmjvsVdvXPz-Swq5v_2UpzZxLGzg27Md817AbY2f_JexCtHarpw1O9iCcJYrEcwoj5ZQKoR9mx5D7UCigST0Ymn9PFlM_RshW38EY5xQCnRDjDveykjuo\" width=\"673\" height=\"82\"><br><br>Now we can print each company &amp; its corresponding current price<\/p>\n\n\n\n<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/eWeo_B9ZaU8kzyjFObpY80q8RUKT4B7-1Nb1oogxz2aS3fIxGdRLypORZVJkwZ4pPn6akiRxE47EM8lkdU7ZRK0BVjAohiD4xzN89tdyFBmHrEFoK1uL4oFcYa5lX2a3d5TPVnKq9TfGCiY_zdvTjsAoO7KldgKe6xwNe3bD2Q95mSWg6iKm42H02lCufeY\" width=\"666\" height=\"73\"><br><br>Run, all companies along with their respective current prices get printed<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/zPt4T8NIC21cu49TOKG4NG22nV9S0AEbI3rYGCUHK5-zNUgY4iCUydNscfj8QaWRw4Z5StydFWWKatCGwtATM3cZkoqW56z1vKAW1Pcoms-o3jNWJeMFIod2pco3cJAZgJVFvaskgM-hE30np4p5J-cNbaZ33Z-w7XKD_jZRVGGO-OMtS1fN2CxiehEaXUI\" alt=\"\"\/><\/figure>\n\n\n\n<p>We are only interested in \u2018<em>JK Lakshmi Cement L<\/em>\u2019, so we can put a simple \u2018if\u2019 condition inside the \u2018for\u2019 loop. This \u2018if\u2019 condition will check, if the \u201ccName\u201d that we have defined in line#13 equals the \u201ccNames\u201d that we are fetching inside the \u2018for\u2019 loop. Once both match, we will print the o\/p<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/9DdNBqx_87QAJyLpuu1fddE3y97PqmbDJyOZjdbMgChz7pUCbCQuq87NQKTRmfxeXtrAPsWcI7Ai36T_UocYnd8OHV3jMUczIyA2C8MQGv-kmmGESghNLwkgKuGgXTNPnp7sAV957m4w61g4-ZmjRviEExaFvaqBn7MiHJqHt0qzsREA4Bw27FOGtYVb5Gc\" alt=\"\"\/><\/figure>\n\n\n\n<p>Run, notice that only desired value is printed&nbsp;<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/vuX_TY4W10Ncv_JNMC3fiAAdmJsN_KBceVwVh1CIE1XSeGNkISlhUbOZBgeLbYwIL5uFf2Kf2V4k2vAc-8JyoTo4wAIY11KCOfW1ExvjLYKoG_OTZ8mYpYKaecn0QypVhv6Lpaa5qV-1cPuMEZyj_bWiQv7euEN1Hgm-myQwKdq8M5R45TukX1hmDIPhk0E\" alt=\"\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/qQeU1IizBSIapGYL-WWiU20QzFyWMR8_x38pNG3H338s99gps5PEzkUunmBBaT7LB7K4wf7_aIogsCr_wHSOEXrbqnRxp7jE8efhyWXelu1lt9YSalv0ssJ6WdJdAS6iCWu6CTqix2Px8PQp2N0jzQWRJd4NoFDk_ckIYjQNEbwJaNNWkxIj9zcMw-rn7i4\" alt=\"\"\/><\/figure>\n\n\n\n<p>Below is complete source code<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-us.googleusercontent.com\/Zw86lu1iYIlYayJsLY6az8mIQo8TKrGmdMxAlpJLfgw1W6fjKvfd2V0LpTRNQTwELAruhoUsGDgc3qSu8cM1m3pepcvKe_Sed-RATSzwMvUpppMgDFZNnj2IbCW_11V3V14U3_MCFoYs4NpFHoXxonoG0QhQhl-PJgXcaGwzRV3we-ZV93US6bYdv0lSmJs\" alt=\"\"\/><\/figure>\n\n\n\n<p>This is how we can handle webtables using selenium webdriver.&nbsp;<\/p>\n\n\n\n<p>Thanks!&nbsp;<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Navigate to https:\/\/money.rediff.com\/index.html Click \u2018More gainers\u2019 link that you see in below figure You get a list of all the companies, see below figure This is an example of Webtable, it is a kind of an excel file where elements are present in a systematic tabular manner. Right click &amp; inspect this Webtable, you will [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1238,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"class_list":["post-2741","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-selenium","post-wrapper","thrv_wrapper"],"_links":{"self":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2741","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/comments?post=2741"}],"version-history":[{"count":10,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2741\/revisions"}],"predecessor-version":[{"id":2827,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/posts\/2741\/revisions\/2827"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media\/1238"}],"wp:attachment":[{"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/media?parent=2741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/categories?post=2741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/rahulshettyacademy.com\/blog\/index.php\/wp-json\/wp\/v2\/tags?post=2741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}