Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99016

How can I find whether element exist?

$
0
0

How can I find whether element exist before using for attribute or if element has label

def getidByLabel(self,driver,target_type,target_label,row_position):
    if target_type == 'form':
        attr_id = driver.find_element_by_xpath("//label[text()='" + target_label + "']").get_attribute("for")
        return attr_id
    elif target_type == 'table':
        attr_id = driver.find_elements_by_xpath("//label[text()='" + target_label + "']").__getitem__(row_position).get_attribute("for")
        return attr_id

Viewing all articles
Browse latest Browse all 99016

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>