首页 > 解决方案 > 如何在webelement中迭代标签?

问题描述

我有这样的html页面:

<div>
    <h3>..</h3>
    <p>..<a>..</a>..</p>
    <p>..</p>
    <h4>..</h4>
</div>

我收到了包含 div 标签的 webelement。在此之后我想在里面迭代标签

h3, p, p, h4 

(我不知道页面中到底有哪些标签)

我怎样才能做到这一点?

我试过了:

driver.find_elements_by_tag_name(but there I need specify tag)

标签: pythonselenium-webdriver

解决方案


items = conteiner.find_elements_by_xpath("""/div/*""")
for item in items:
   print(item.tag_name)
   print(item.get_attribute('innerHTML'))

推荐阅读