I'm very new to Selenium with Python and I'm simply trying to click 2 consecutive buttons on this website: https://www.wunderground.com/history/daily/gb/manchester/EGCC/date/2017-8-28
I want to click the settings icon in the top right corner and then click the celsius option to convert temperatures on the site.
I can achieve this whilst debugging the code and doing the steps one at a time, but when I run the code normally, it is unable to find the second element with the error:
NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="wuSettings-quick"]/div/a[2]"}
(Session info: chrome=85.0.4183.83)
I have tried identifying the elements by id and xpath as follows:
Button 1: driver.find_element_by_id('wuSettings').click()
Button 2: driver.find_element_by_xpath('//*[@id="wuSettings-quick"]/div/a[2]').click()
Hoping it's an easy fix. All help appreciated. Thanks.
Code below:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
driver.get("https://www.wunderground.com/history/daily/gb/manchester/EGCC/date/2017-8-28")
driver.implicitly_wait(15)
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'wuSettings'))
)
element.click()
# element = WebDriverWait(driver, 10).until(
# EC.presence_of_element_located((By.XPATH, '//*[@id="wuSettings-quick"]/div/a[2]'))
# )
# element.click()
except:
driver.quit()