Reputation: 89
I am very new to Selenium and Python in general. I want to get the title of a td class, the HTML code looks like this. I only need to get the 6,012,567 number to use later:
<td class="infoStats__stat link-light border-light-right">
<a href=“/follow" class="infoStats__statLink link-light" title="6,012,567">
<h3 class="infoStats__title font-light”>Users</h3>
<div class="infoStats__value font-tabular-light">6.01M</div>
</a>
</td>
So far I have this:
#element = WebDriverWait(driver, 2).until(EC.presence_of_element_located((By.XPATH, '//td[contains(@class, "infoStats__statLink")]')))
#users = int(element.text.replace(',', ''))
But this is just giving me the 6.01 abbreviation, is there a better way to do this?
Upvotes: 2
Views: 3883
Reputation: 52665
Use following code to get required value:
value = int(driver.find_element_by_xpath('//a[@class="infoStats__statLink link-light"]').get_attribute("title"))
Let me know if any errors occurs
Upvotes: 3
Reputation: 17553
Use the below XPath:-
//a[@class='infoStats__statLink link-light']/@title
Use code as below :-
elem = driver.find_elements_by_xpath("//a[@class='infoStats__statLink link-light']/@title");
print elem.text
Hope it will help you :)
Upvotes: 0