I am trying to code a code that returns the weather of a city. For this I use selenium (I know there is better libraries but this is the one I am most comfy with). First I make the code search "weather xxx" and then use the google feature that automatically displays all infos.
Then I for example select the temperarture, there is th HTML, 3 is the value I want to print:
<span class="wob_t q8U8x" id="wob_tm" style="display:inline">3</span>
But when I print it returns:
<selenium.webdriver.remote.webelement.WebElement (session="fb232f60015b08ee6db42b7fa83bd990", element="50c95ed2-17ce-41eb-835a-e7f9d0360540")>
How can I transform or navigate the output or xpath to get the value? (3)
Full code:
from selenium.webdriver.common.keys import Keys as k
from selenium import webdriver
from selenium.webdriver.common.by import By
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://google.com/")
def process():
global temperature
driver.find_element(By.XPATH,'//*[@id="L2AGLb"]/div').click()
driver.find_element(By.NAME,'q').send_keys(city, ' weather'+k.RETURN)
temperature = driver.find_element(By.ID,'wob_tm')
city = input('City: ')
process()
print(temperature)
driver.quit()
P.S, I am using ID to locate the element but it returns the same "weird" output with XPATH etc...
Thanks for your help