Home > database >  python selenium clicking a list object
python selenium clicking a list object

Time:11-30

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?

CodePudding user response:

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()

CodePudding user response:

Maybe change the last line to; driver.find_element

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

  • Related