I want to grep the total number of deaths from the Johns Hopkins Covid dashboard. I want to do this using Selenium, Python and Selenium’s chrome driver. The number of deaths can be found under the path //*[@id="ember1915"]/svg/g[2]/svg/text
.
This is my script:
from selenium.webdriver import Chrome
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
with Chrome() as driver:
driver.get('https://coronavirus.jhu.edu/map.html')
driver.implicitly_wait(20) # Waits for 20 s for the entire page to loads.
diplayElement = driver.find_element_by_xpath('//*[@id="ember1915"]/svg/g[2]/svg/text')
It fails with the error “no such element:
Unable to locate element: {"method":"xpath","selector":"//*[@id="ember1915"]/svg/g[2]/svg/text"}”.
This also happens for other sites I’m trying to scrape.
How can I fix this? What’s the reason for this error?