0

My code accesses a page, and I am trying to click on the button that says "Program" on the menu bar (between the words "Abstract" and "Awards")

There is a href in the html of the page that would direct me to this new page, however I am not able to click on it using selenium?

It gives this error - list' object has no attribute 'click'

here is my code

import time
from bs4 import BeautifulSoup
from selenium import webdriver
driver = webdriver.Chrome()

driver.get('https://www.kidney.org/spring-clinical/program')
time.sleep(2)
page_source = driver.page_source
soup = BeautifulSoup(page_source, 'html.parser')
element1 = driver.find_elements_by_xpath('/html/body/div[2]/nav/div/div[1]/div[3]/a')
element1.click()
0

1 Answer 1

1

find_elements_by_xpath() returns list of element and you can't click on list.

Change this to either find_element_by_xpath() which returns webelement

element1 = driver.find_element_by_xpath('/html/body/div[2]/nav/div/div[1]/div[3]/a')
element1.click()

Or use index

element1 = driver.find_elements_by_xpath('/html/body/div[2]/nav/div/div[1]/div[3]/a')
element1[0].click()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.