[英]Can't get text inside strong tag
<div class="some_class>
<p>
<strong>
some text
</strong>
</p>
</div>
I try to use driver.find_element_by_xpath("xpath to strong tab").text but this print empty string我尝试使用 driver.find_element_by_xpath("xpath to strong tab").text 但这打印空字符串
Could you try printing the textContent Attribute if text is not in view port or is not displayed:如果文本不在视口中或未显示,您能否尝试打印 textContent 属性:
driver.find_element_by_xpath("xpath to strong tab").get_attribute("textContent")
ALso you could try你也可以试试
strong = driver.find_element_by_xpath("xpath to strong tab")
driver.execute_script("arguments[0].scrollIntoView()",strong)
print(strong.text)
This will bring the element into view这将使元素进入视野
There are chances that there are multiple <strong>
tabs in your page.您的页面中可能有多个
<strong>
标签。
Try the following:尝试以下操作:
allStrongs = driver.find_elements_by_xpath("xpath to strong tab")
for aStrong in allStrongs:
print(aStrong.text)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.