有没有办法获取硒web元素标签的名称?
我发现,对于Java,硒中有.getTagName()
,在此处:https://www.tutorialspoint.com/how-do-i-get-a-parent-html-tag-with-selenium-webdriver-using-java
编辑:
示例:在此HTML中,如果我通过class ='some_class_name'进行迭代,那么如何获取标记名(h2
,p
,ul
或li
)
<div class='some_class_name'>
<h2>Some Random Heading 1</h2>
<p>Lorem Ipsum is simply dummy text of the printing and typesetting industry</p>
<h2>Some Random Heading 2</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</p>
<p>Random list are:</p>
<ul>
<li>Lorem</li>
<li>Ipsum</li>
<li>Dolor</li>
</ul>
</div>
Python代码可能看起来像这样。
content = driver.find_elements_by_xpath("//div[@class='some_class_name']//child::*")
for c in content:
print(c.getTagName()) # something like this to get the tag of inner content..
答案 0 :(得分:1)
Python,您有tag_name
来获取标签名称。
content = driver.find_elements_by_xpath("//div[@class='some_class_name']//child::*")
for c in content:
print(c.tag_name)