Python Forum

Full Version: Python Selenium getting table element
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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>
Do you have a URL for this page?
@Larz60+, Due to security concerns, I am unable to share the url. Does it look like it has errors?