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.
(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()
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.
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
>>>
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
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 ?
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 ?
Ok seems I have solved the problem.