Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python selenium get tag value of a selected element

I'm using the code below to find all the elements with class value = "ng_isolate_scope". What I would need to do though is to capture the tag value of the selected elements, since I need this information for further analysis

<span class="ng-isolate-scope">
<div class="ng-isolate-scope">

Code:

elems = driver.find_elements_by_class_name("ng-isolate-scope")
for elem in elems:
    tag_value = elem.get_tag()
    print("element found with tag value = " + str(tag_value))

However, tag_value() doesn't exist. What can I do to capture the tag value of an element? Thanks

like image 739
Angelo Avatar asked Sep 18 '25 01:09

Angelo


1 Answers

updated: Its bit tricky, here my approach is to get outerHTML of element and then splitting the first word (which is tag name). So you can try:

    elements = driver.find_elements_by_class_name("ng-isolate-scope")
    for element in elements:
      outerhtml = element.get_attribute('outerHTML ') // to extract outerHTML 
      tag_value=outerhtml.split('',1)[0] // to extract first word
      print("element found with tag value = " + tag_value)
like image 61
theGuy Avatar answered Sep 19 '25 17:09

theGuy