0

I'm having trouble getting the inner text of a web element on this page (Using VBA + Selenium): https://www.accuweather.com/en/ch/geneva/313082/daily-weather-forecast/313082?day=2

I'm trying to get the text (The "20°") in the following element:

<div class="temperature" style="">20°</div>

I tried using mystring = driver.FindElementByCss(".row.first > .temperature:nth-of-type(2)").text but for some reason it doesn't seem to work, it returns an empty value in Excel, as if it's not getting anything from the element.

I'd appreciate any help, I've been trying to get this working for a little while now.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Bloggy
  • 109
  • 12
  • Does it need a wait before? I would also use .history .temperature as the css selector – QHarr Aug 30 '20 at 22:35
  • driver.findElementByClassName("temperature").text Try to see if it's the text getting error cause of the weird symbol or the css selector? – Arundeep Chohan Aug 31 '20 at 02:10

1 Answers1

0

To get the inner text of a web element i.e. 21° using VBA and Selenium you can use either of the Locator Strategies:

  • FindElementByXPath:

    mystring = driver.FindElementByXPath("//h2[@class='title' and text()='Day']//following-sibling::div[@class='temperature']").text
    
  • FindElementByCss:

    mystring = driver.FindElementByCss("div.content-module div:nth-of-type(2) div.temperature").text
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352