I am trying to get date from HTML using selenium. The problem is, that in the HTML (if viewed through the console in a browser) I see the full date like 01.01.2001, but selenium returns me 01.January what I should do, to get full date?
The part of HTML(what I see in the browser console) looks like this:
<div>
<h4 class="status-param"> Name and Surname </h4>
<h4 class="status-param"> Date of Birth: 01.01.2001 </h4> <!--problem only with this -->
<h4 class="status-param"> 12.12.2012 00:00 </h4>
</div>
my code
driver = webdriver.Chrome('chrome/chromedriver')
driver.get(html)
result = []
try:
elements = WebDriverWait(driver, 10).until(
EC.presence_of_all_elements_located((By.CLASS_NAME, "status-param"))
)
for element in elements:
result.append(element.text)
finally:
driver.quit()
I get the following
'Name and Surname'
'Date of Birth: 01.January'
'12.12.2012'
use the below xpath :
(//div/h4[@class='status-param'])[2]
and use it like this :
elements = WebDriverWait(driver , 10).until(EC.visibility_of_element_located((By.XPATH, "(//div/h4[@class='status-param'])[2]"))).get_attribute('innerHTML')
print(elements)
the above should only prints 01.01.2001
Update 1 :
You can simply break string into 2 parts ang grab the second part like this :
print(elements.split("\\:")[1])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.