Python Forum
Python Selenium getting table element
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python Selenium getting table element
#1
I have a html table and I want to use Selenium/Python to grab a certain table data element that has the role of a gridcell (I am new to this). Below is html code of table body and highlighted is the element desired (with text US_Domain). It is clickable.

Here are some things I tried:

1.Finding item directly - this found nothing

td = driver.find_elements_by_xpath('//tbody//tr//td')
for tableData in td:
cellData = tableData.text
print(cellData)
if cellData == 'US_Domain':
domain_button = tableData
break

2.Finding table and then item - couldn't find table

table = wait.until(EC.presence_of_element_located((By.CSS_SELECTOR, "table.k-selectable")))
for row in table.find_elements_by_xpath(".//tr"):
cell = row.find_elements_by_tag_name("td")[4]

I also tried finding table by `table = wait.until(EC.presence_of_element_located((By.XPATH, "/*[@id='AccountsGrid']/div[2]/table"))).


Here is the html code:

<tbody role="rowgroup"><tr data-uid="2b836654-6608-4753-b611-338c0109550e" role="row" class=""><td style="display:none" role="gridcell">26080</td><td class="favorite-action" role="gridcell">
<a title="Remove From Favorites" class="favlink filled " href="#"></a>
</td><td style="display:none" role="gridcell">20247</td><td role="gridcell">US_Domain</td><td style="" role="gridcell">


<button class="btn onecl qlGridButtonFinger" title="OneClick launch"></button>


</td><td style="display:none" role="gridcell">31913</td><td role="gridcell">us.xxxxxxxx</td><td role="gridcell">xxxxx</td><td class="description" data-selector="true" data-toggle="popover" role="gridcell">AD (Owner: xxxxxxxx, Dept: xxxxxxxx)</td><td class="status" role="gridcell">
<span class="level green"></span>
<span class="display">Unlimited</span>
</td><td style="display:none" role="gridcell">true</td><td style="display:none" role="gridcell">1</td><td role="gridcell">Windows</td><td style="display:none" role="gridcell">true</td><td style="display:none" role="gridcell">true</td><td style="display:none" role="gridcell">true</td><td style="display:none" role="gridcell">true</td><td style="display:none" role="gridcell">0</td><td style="display:none" role="gridcell">12</td><td style="display:none" role="gridcell">0</td><td style="display:none" role="gridcell">0</td><td style="display:none" role="gridcell">12</td><td style="display:none" role="gridcell">0</td><td style="display:none" role="gridcell"></td><td style="display:none" role="gridcell">false</td><td style="display:none" role="gridcell">true</td><td style="display:none" role="gridcell">false</td><td style="display:none" role="gridcell">false</td><td style="display:none" role="gridcell"></td><td role="gridcell"></td><td role="gridcell"></td><td class="directconnect" role="gridcell">

<a class="gridicon download" data-placement="left" data-selector="true" data-container="body" title="Download RDP Direct Connect file" href="#" data-toggle="popover"></a>

</td><td role="gridcell" style="display: none;"></td></tr></tbody>
Reply
#2
Do you have a URL for this page?
Reply
#3
@Larz60+, Due to security concerns, I am unable to share the url. Does it look like it has errors?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium returning web element instead of desired text newbie_programmer 2 7,573 Nov-12-2024, 07:27 PM
Last Post: brownbanned
  Selenium suddenly fails to find element Pavel_47 3 9,932 Sep-04-2022, 11:06 AM
Last Post: Pavel_47
  Selenium does not keep the table? euras 1 2,939 Jun-05-2021, 11:17 AM
Last Post: Monish
  Clicking on element not triggering event in Selenium Python (Event Key is not in data dkaeloredo 2 5,294 Feb-16-2020, 05:50 AM
Last Post: dkaeloredo
  How get table element zinho 5 3,764 Dec-28-2019, 09:25 PM
Last Post: snippsat
  Selenium locating an element. JokerTux 3 3,532 Dec-28-2019, 08:50 AM
Last Post: snippsat
  Click Element if displayed using Selenium and Python giaco__mar 1 4,498 Dec-27-2018, 06:19 PM
Last Post: metulburr
  Selenium stale element reference test 1 3,387 Sep-19-2018, 10:19 PM
Last Post: test
  Simple Element Check Code in Selenium Not Working digitalmatic7 1 3,534 Feb-18-2018, 06:53 AM
Last Post: metulburr
  Selenium - Googlemaps element not visible Barnettch3 3 6,814 Jan-15-2018, 08:07 PM
Last Post: Barnettch3

Forum Jump:

User Panel Messages

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