有没有办法获取selenium web元素标记的名称
我发现,seleniumforjava中有.getTagName()
,这里:https://www.tutorialspoint.com/how-do-i-get-a-parent-html-tag-with-selenium-webdriver-using-java
编辑:
示例:在这个HTML中,如果我遍历class='some_class='u 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..
Python您有
tag_name
来获取标记名相关问题 更多 >
编程相关推荐