Issue
Is there any way to get name of the tag of selenium web element??
I found, there is .getTagName()
in selenium for java, here:https://www.tutorialspoint.com/how-do-i-get-a-parent-html-tag-with-selenium-webdriver-using-java
EDIT:
example: In this HTML, if I iterate though class='some_class_name', how can I get the tag_name (h2
, p
, ul
or 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 code may look like this..
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..
Solution
Python you have tag_name
to get the tag name.
content = driver.find_elements_by_xpath("//div[@class='some_class_name']//child::*")
for c in content:
print(c.tag_name)
Answered By - KunduK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.