selenium how to get the content of href within some targeted class selenium how to get the content of href within some targeted class python python

selenium how to get the content of href within some targeted class


As far as I am aware you can get the href by searching through the child elements

div = self.driver.find_element_by_class_name('someclass')div.find_element_by_css_selector('a').get_attribute('href')


This should do it for you:

self.driver.find_element_by_css_selector('.someclass a').get_attribute('href')


if you search for special tag use from find_element_by_id or classname or xpathand then use get_attribute('href')

in this example print all attribute for a tags

   ids = self.driver.find_elements_by_xpath('//*[@href]')   for id in ids:        print(id.get_attribute('href'))