Python Forum
Click on a button on web page using Selenium
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Click on a button on web page using Selenium
#1
Hello,

Here is example where I'm looking for a solution to click on button "Lire plus" on this page:
1 km à pied
Here is my snippet:
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.common.by import By options = Options() options.add_argument("--headless") browser = webdriver.Chrome('/usr/bin/chromedriver', options=options) url = 'https://www.arte.tv/fr/videos/103475-006-A/1-km-a-pied/' browser.get(url) buttons = browser.find_elements(By.TAG_NAME, "button") for button in buttons: if button.text == "Lire plus": button.click()
Here is output:
Output:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (104, 1102) (Session info: headless chrome=102.0.5005.61)
Any suggestions.
Thanks.
Reply
#2
(Jul-16-2022, 02:34 PM)Pavel_47 Wrote: Here is example where I'm looking for a solution to click on button "Lire plus" on this page:
You most by most more specific than just button there are many buttons on site.
Don't use --headless when test stuff out or will not see if it work.
Test this work.
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains import time #--| Setup options = Options() #options.add_argument("--headless") ser = Service(r"C:\cmder\bin\chromedriver.exe") browser = webdriver.Chrome(service=ser, options=options) #--| Parse or automation url = "https://www.arte.tv/fr/videos/103475-006-A/1-km-a-pied/" browser.get(url) time.sleep(5) lire = browser.find_element(By.CSS_SELECTOR, '#__next > div > main > div.css-p6yk9l > div.css-5mui6u > div > button') lire.click() time.sleep(5) lire_close = browser.find_element(By.CSS_SELECTOR, '#__next > div > main > div.css-p6yk9l > div.css-5mui6u > div > button') lire_close.click()
Reply
#3
Thanks.
Tried your approach.
Doesn't work - the similar message:

Output:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (104, 1145) (Session info: chrome=102.0.5005.61)
In fact what I'm looking for is to access data that only becomes visible if the "Lire plus" section is expanded.
There is probably another solution. Anyway, when I search for data related to "Lire plus" (ex. Réalisation, Scénario), it is not found.
Reply
#4
Tried to use WebDriverWait.
Doesn't work either.

from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException, ElementClickInterceptedException import time options = Options() driver = webdriver.Chrome('/usr/bin/chromedriver', options=options) url = 'https://www.arte.tv/fr/videos/103475-006-A/1-km-a-pied/' driver.get(url) timeout = 10 try: button_lire_plus = WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.CSS_SELECTOR, '#__next > div > main > div.css-p6yk9l > div.css-5mui6u > div > button'))) button_lire_plus.click() except TimeoutException: print('Failed to locate button') except ElementClickInterceptedException: print('Can\'t click on button') finally: driver.quit() driver.quit()
Here is output in shell:
Output:
>>> RESTART: /home/pavel/python_code/explore_arte_with_selenium_test_click_button_v2.py Can't click on button >>>
Reply
#5
Try serval time something i get ElementClickInterceptedException.
Now just use sleep(5) as test selenium as owns waits
Parse test of content in Lire plus.
from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.chrome.service import Service from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.action_chains import ActionChains import time #--| Setup options = Options() #options.add_argument("--headless") ser = Service(r"C:\cmder\bin\chromedriver.exe") browser = webdriver.Chrome(service=ser, options=options) #--| Parse or automation url = "https://www.arte.tv/fr/videos/103475-006-A/1-km-a-pied/" browser.get(url) time.sleep(5) lire = browser.find_element(By.CSS_SELECTOR, '#__next > div > main > div.css-p6yk9l > div.css-5mui6u > div > button') lire.click() time.sleep(3) content = browser.find_element(By.CSS_SELECTOR, 'div.css-5pryf8 > div.css-m3r1o3 > div.css-vhqfin') print(content.text)
Output:
Réalisation : Pierre Lazarus Scénario : Emmanuelle Moreau Noémie Parreaux Production : Filmakademie Baden-Württemberg SWR ARTE Producteur/-trice : Giacomo Vernetti Prot Jennifer Miola Image : Hovig Hagopian Montage : Mathieu Pluquet Musique : Louis-Ronan Choisy
Reply
#6
Tried. Still get this:
Output:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (104, 1145) (Session info: chrome=102.0.5005.61)
Perhaps should I change some options in Chrome ?
Reply
#7
Well ... here is solution that works also at my side:

from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from selenium.common.exceptions import TimeoutException, ElementClickInterceptedException options = Options() driver = webdriver.Chrome() url = 'https://www.arte.tv/fr/videos/103475-006-A/1-km-a-pied/' driver.get(url) timeout = 10 button_location = '#__next > div > main > div.css-p6yk9l > div.css-5mui6u > div > button' try: button_lire_plus = WebDriverWait(driver, timeout).until(EC.presence_of_element_located((By.CSS_SELECTOR, button_location))) driver.execute_script('arguments[0].click()', button_lire_plus) content = driver.find_element(By.CSS_SELECTOR, 'div.css-5pryf8 > div.css-m3r1o3 > div.css-vhqfin') print(content.text) except TimeoutException: print('Failed to locate button') except ElementClickInterceptedException: print('Can\'t click on button') finally: driver.quit() driver.quit()
I'm wondering does exist some other solution allowing to access this data in headless mode ?
Reply
#8
Ok seems I have solved the problem.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  cant click button by script at page michael1834 1 2,854 Dec-08-2023, 04:44 PM
Last Post: SpongeB0B
  Selenium press "select option" button (SOLVED) kucingkembar 0 1,925 Aug-10-2023, 11:49 AM
Last Post: kucingkembar
  How to make use of this button with selenium? Nohah 0 1,890 Sep-22-2022, 10:22 AM
Last Post: Nohah
  Selenium/Helium loads up a blank web page firaki12345 0 3,319 Mar-23-2021, 11:51 AM
Last Post: firaki12345
  button click error rafarangel 2 4,639 Feb-11-2021, 08:19 PM
Last Post: buran
  Saving html page and reloading into selenium while developing all xpaths Larz60+ 4 7,034 Feb-04-2021, 07:01 AM
Last Post: jonathanwhite1
  Selenium Parsing (unable to Parse page after loading) oneclick 7 8,766 Oct-30-2020, 08:13 PM
Last Post: tomalex
  Selenium Page Object Model with Python Cryptus 5 7,488 Aug-19-2020, 06:30 AM
Last Post: mlieqo
  Selenium on Angular page Martinelli 3 8,720 Jul-28-2020, 12:40 PM
Last Post: Martinelli
  Unable to click element in web page Kalpana 0 2,757 Jun-25-2020, 05:20 AM
Last Post: Kalpana

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.