Python Forum
How to get specific TD text via Selenium?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get specific TD text via Selenium?
#4
Can use CSS selector .find_element_by_css_selector
If getting first name eg Jill, body > table > tbody > tr:nth-child(2) > td:nth-child(1)(can copy selector from Browser).
Then the loop to get would be like this for getting all first name in table.
for n in range(2, 5):
    tag = f'body > table > tbody > tr:nth-child({n}) > td:nth-child(1)'
    print(tag)
Output:
body > table > tbody > tr:nth-child(2) > td:nth-child(1) body > table > tbody > tr:nth-child(3) > td:nth-child(1) body > table > tbody > tr:nth-child(4) > td:nth-child(1)
<table style="width:100%">
  <tr>
    <th>Firstname</th>
    <th>Lastname</th>
    <th>Age</th>
  </tr>
  <tr>
    <td>Jill</td>
    <td>Smith</td>
    <td>50</td>
  </tr>
  <tr>
    <td>Eve</td>
    <td>Jackson</td>
    <td>94</td>
  </tr>
</table>
Reply


Messages In This Thread
RE: How to get specific TD text via Selenium? - by snippsat - May-14-2021, 05:12 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  selenium wait for text question Larz60+ 3 2,567 Oct-25-2021, 09:50 AM
Last Post: Larz60+
  Selenium innerHTML list, print specific value denis22934 2 3,279 Jun-14-2021, 04:59 AM
Last Post: denis22934
  With Selenium create a google Search list in Incognito mode withe specific location, tsurubaso 3 3,282 Jun-15-2020, 12:34 PM
Last Post: tsurubaso
  Selenium extract id text xzozx 1 2,137 Jun-15-2020, 06:32 AM
Last Post: Larz60+
  Getting text using Selenium WiPi 10 4,858 Apr-27-2020, 08:58 AM
Last Post: WiPi
  Web crawler extracting specific text from HTML lewdow 1 3,410 Jan-03-2020, 11:21 PM
Last Post: snippsat
  Selenium returning web element instead of desired text newbie_programmer 1 5,204 Dec-11-2019, 06:37 AM
Last Post: Malt
  Getting a specific text inside an html with soup mathieugrimbert 9 15,961 Jul-10-2019, 12:40 PM
Last Post: mathieugrimbert
  XML Parsing - Find a specific text (ElementTree) TeraX 3 4,079 Oct-09-2018, 09:06 AM
Last Post: TeraX
  webscraping - failing to extract specific text from data.gov rontar 2 3,210 May-19-2018, 08:01 AM
Last Post: rontar

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020