Jun Yu
Jun Yu

Reputation: 424

how to read hidden text in python by using selenium?

I use selenium in python to read table data from a website. I want to get data1 and data2. I use the code like below. But I can only get the data2, the first code will print nothing. Can anyone tell me how to solve this problem? Thank you.

elem = browser.find_element_by_css_selector('td.el-table_1_column_1.is-hidden div')
print(elem.text)
elem = browser.find_element_by_css_selector('td.el-table_1_column_2 div')
print(elem.text)
<td class="el-table_1_column_1   is-hidden">
    <div class="cell">data1</div>
</td>
<td class="el-table_1_column_2  ">
    <div class="cell">data2</div>
</td>

Upvotes: 1

Views: 549

Answers (1)

KunduK
KunduK

Reputation: 33384

Use elem.get_attribute("textContent") to get the hidden value from node.

elem = browser.find_element_by_css_selector('td.el-table_1_column_1.is-hidden div')
print(elem.get_attribute("textContent"))

Please check the following Link

Upvotes: 1

Related Questions