0

As an exercise, I want to get the confirmed cases and the deaths value from this site (at the top left) via Selenium.

Ive tried it with xPath but it doesn't work! f.e.:

worldInfected = driver.find_element_by_xpath("//*[@id=\"ember584\"]/svg/g[2]/svg/text")

If I use this I get

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div/div/div[2]/div/div/div/margin-container/full-container/div[2]/margin-container/full-container/div/div/div/div[1]/svg/g[2]/svg/text

but I copied the path from the website so shouldn't it give me the text

I've tried it with the same strategy on other websites and it worked.. Does it have something to do with this exact website and if so is there another way to crawl this information?

Thank you for helping me in advance! <3

JGStyle
  • 147
  • 12
  • 1
    Saying "it doesn't work" isn't much of an explanation. What does it _actually do_, and how is that different from what you _expected_? – John Gordon Mar 18 '20 at 21:59
  • 1
    Also, just because a specific xpath works with one website, why would you expect it to work on a different site? Different sites are different. – John Gordon Mar 18 '20 at 22:00
  • Maybe attach the screenshot of html or the element that you're trying to locate? I opened the url you have mentioned, and I don't see anything with ID `ember584` – Svetlana Levinsohn Mar 18 '20 at 22:04
  • 1
    Duplicate ? You have answers here : https://stackoverflow.com/questions/60730105/selenium-not-finding-element-by-xpath-although-visible-in-browser/60744766 – E.Wiest Mar 19 '20 at 00:35
  • obviously I didnt just use the path from another site, I copied the path from the element that I want the text of from the site mentioned – JGStyle Mar 19 '20 at 09:08

1 Answers1

0

Dear please modify the xpath like this, and i think will be working

worldInfected = driver.find_element_by_xpath('//*[@id=\"ember584\"]/svg/g[2]/svg/text')

NOTE: If not working please describe more

Munna
  • 19
  • 2
  • this literally doesn't change anything. – JGStyle Mar 19 '20 at 09:12
  • I just want the number of how many people are infected on the world from the website linked in the post – JGStyle Mar 19 '20 at 09:13
  • 1
    @debanjanb provides a well detailed answer here :https://stackoverflow.com/a/60743834/9978746 Did you read it ? You have to switch to the iframe first. – E.Wiest Mar 19 '20 at 12:16