python selenium clicking a list object

Question:

I am trying to click 1 Min button on this site

below is my python code

url = 'https://www.investing.com/technical/technical-analysis'
driver.get(url)
events = WebDriverWait(driver, 30).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "section#leftColumn")))
print("Required elements found")
events.find_element(By.XPATH,"//a[text()='1 Min']").click()

Am getting the following error:
events.find_element(By.XPATH,"//a[text()=’1 Min’]").click()
AttributeError: ‘list’ object has no attribute ‘find_element’

What can I change in the code to click the ‘1 Min’ button succesfully?

Asked By: Aliko Aliko

||

Answers:

Maybe change the last line to;
driver.find_element

Also you can check for that XPATH with WebDriverWait until located.

Answered By: Erik Nilsen

You have to use 'for' loop to iterate through all the elements in 'events' element:

events = WebDriverWait(driver, 30).until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, "section#leftColumn")))
print("Required elements found")
for event in events:
    event.find_element(By.XPATH,"//a[text()='1 Min']").click()
Answered By: AbiSaran