Void S
Void S

Reputation: 802

Click button on JS page -Python

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

Upvotes: 0

Views: 96

Answers (1)

KunduK
KunduK

Reputation: 33384

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

Upvotes: 1

Related Questions