younggotti
younggotti

Reputation: 822

Python/Selenium - Click on button

I'm trying to make Selenium click on a button to follow a link (it's the "Previous Month" button below the table): https://www.interactivebrokers.eu/en/index.php?f=39108

I tried the following

from selenium import webdriver

url = 'https://www.interactivebrokers.eu/en/index.php?f=39108'

driver = webdriver.Chrome("C:\\Users\\domen\\anaconda3\\Lib\\site-packages\\chromedriver_py\\chromedriver_win32.exe")

driver.get(url)
button = driver.find_element_by_css_selector('#monthly-interest-rates > div > div > div > div:nth-child(5) > a.btn.btn-sm.btn-default')
button.click()

but I get the following error: ElementClickInterceptedException: Message: element click intercepted: Element ... is not clickable at point (367, 916). Other element would receive the click: ...

I got the same error with:

button = driver.find_element_by_link_text("Previous Month").click()

I also tried the following two alternatives:

button = driver.find_element_by_xpath('/html/body/div[3]/section[2]/div/div/div/div[2]/a[1]')
button = driver.find_element_by_class_name('btn btn-sm btn-default')

but I got: NoSuchElementException: Message: no such element: Unable to locate element

Does anyone can help? Thanks

Upvotes: 0

Views: 122

Answers (3)

Renato Alves
Renato Alves

Reputation: 37

You can change .click() to .send_keys(Keys.ENTER).

I was trying that with the selector provided by you but it was clicking in another element, it was only going to second page, not downloading.

from selenium.webdriver.common.keys import Keys
button.send_keys(Keys.ENTER)

Upvotes: 0

Faizan
Faizan

Reputation: 1

from selenium import webdriver
url = 'https://www.interactivebrokers.eu/en/index.php?f=39108'
driver = webdriver.Chrome("C:\\Users\\domen\\anaconda3\\Lib\\site- 
packages\\chromedriver_py\\chromedriver_win32.exe")

driver.get(url)
button = driver.find_element_by_xpath('//*[@id="monthly-interest- 
rates"]/div/div/div/div[2]/a[1]').click()
button

Upvotes: 0

itronic1990
itronic1990

Reputation: 1441

You have to accept the cookies displayed at the bottom of the page

driver.find_element_by_xpath("//a[@id='btn_accept_cookies']").click()

Upvotes: 1

Related Questions