-1
<div class="some_class>    
  <p>
   <strong>
     some text
   </strong>
  </p>
</div>

我尝试使用 driver.find_element_by_xpath("xpath to strong tab").text 但这打印空字符串

4

2 回答 2

0

如果文本不在视口中或未显示,您能否尝试打印 textContent 属性:

 driver.find_element_by_xpath("xpath to strong tab").get_attribute("textContent")

你也可以试试

strong = driver.find_element_by_xpath("xpath to strong tab")
driver.execute_script("arguments[0].scrollIntoView()",strong)
print(strong.text)

这将使元素进入视野

于 2021-02-09T08:40:34.297 回答
0

<strong>您的页面中可能有多个选项卡。

尝试以下操作:

allStrongs = driver.find_elements_by_xpath("xpath to strong tab")

for aStrong in allStrongs:

     print(aStrong.text)

于 2021-02-09T10:28:48.373 回答