Example code “`
<span class="_7UhW9 xLCgt qyrsm KV-D4 se6yk T0kll ">cristiano</span>
How to tell python to find every element with *class*, *title*, *href*, and *tabindex* attributes. Then get the "title" value for each.
tried find_element_by_xpath but no result
>Solution :
The syntax is "//*[@attribute_name]" i.e.
to get all the elements with title attribute the XPath is "//*[@title]",
to get all the elements with class attribute the XPath is "//*[@class]",
to get all the elements with href attribute the XPath is "//*[@href]"
etc.
So, to get all the title attribute values from all the elements on the page you can do something like this:
elements = driver.find_elements(By.XPATH, "//*[@title]")
for element in elements:
title = element.get_attribute("title")
print(title)
etc.
In case you want to locate all elements having title and class and href attributes, all the 3 in each all of them, it will look like this:
elements = driver.find_elements(By.XPATH, "//*[@title and @class and @href]")
for element in elements:
title_val = element.get_attribute("title")
class_val = element.get_attribute("class")
href_val = element.get_attribute("href")
print(title_val)
print(class_val)
print(href_val)