Задать вопрос
Maxim2p12
@Maxim2p12

Как пофиксить selenium.common.exceptions.ElementClickInterceptedException?

Есть скрипт, который перебирает все елементы в списке, найденые на странице, сравнивает есть ли в названии любая буква с строки required_letters, если есть, то нажимает на елемент и ищет поля author, link_on_profile, social_media_link. Создает екзампляр класа и добавляет в множество mapmakers. И в конце возвращается на страницу со всемя картами и обновлят страницу, но возникает ошибка selenium.common.exceptions.ElementClickInterceptedException, что делать?

Код
import time

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import Chrome, ChromeOptions
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException


driver = Chrome()
url = 'https://sc2arcade.com/map-list'
driver.get(url)
maps_names = driver.find_elements(By.CLASS_NAME, 'title')
options = ChromeOptions()
options.add_argument("--disable-notifications")


required_letters = 'qwertyuiopasdfghjklzxcvbnm'


class MapMaker:
    def __init__(self, username, social_media_link, link_to_profile):
        self.username = username
        self.social_media_link = social_media_link
        self.link_to_profile = link_to_profile

    def __eq__(self, other):
        if isinstance(other, MapMaker):
            return self.value == other.value
        return False

    def __hash__(self):
        return hash(self.value)


mapmakers = set()


for map_name in maps_names:
    for required_letter in required_letters:
        for letter in map_name.text:
            if letter == required_letter:
                map_name.click()
                try:
                    author = driver.find_element(By.CLASS_NAME, 'v-avatar v-list-item__avatar rounded-0 v-avatar--tile').text
                    link_on_profile = driver.find_element(By.CLASS_NAME, 'player-link').text
                    social_media_link = driver.find_element(By.CLASS_NAME, 'v-btn__content').text

                    mapmaker = MapMaker(author, link_on_profile, social_media_link)
                    mapmakers.add(mapmaker)
                    
                    driver.back()
                    driver.refresh()
                except NoSuchElementException:
                    pass


print(mapmakers)


Вывод в консоль:
Traceback (most recent call last):
  File "C:\Users\ACER NITRO\VScode Projects\sc2arcade_parser\main.py", line 44, in <module>
    map_name.click()
  File "C:\Users\ACER NITRO\VScode Projects\sc2arcade_parser\venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 94, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Users\ACER NITRO\VScode Projects\sc2arcade_parser\venv\Lib\site-packages\selenium\webdriver\remote\webelement.py", line 395, in _execute
    return self._parent.execute(command, params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ACER NITRO\VScode Projects\sc2arcade_parser\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 380, in execute
    self.error_handler.check_response(response)
  File "C:\Users\ACER NITRO\VScode Projects\sc2arcade_parser\venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 229, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <h4 class="title">...</h4> is not clickable at point (437, 254). Other element would receive the click: <iframe id="aswift_3" name="aswift_3" browsingtopics="true" style="width: 100vw !important; height: 100vh !important; inset: 0px auto auto 
0px !important; position: absolute !important; clear: none !important; display: inline !important; float: none !important; margin: 0px !important; max-height: none !important; max-width: none !important; opacity: 1 !important; overflow: visible !important; padding: 0px !important; vertical-align: baseline !important; visibility: visible !important; z-index: auto !important;" sandbox="allow-forms allow-popups allow-popups-to-escape-sandbox allow-same-origin allow-scripts allow-top-navigation-by-user-activation" width="" height="" frameborder="0" marginwidth="0" marginheight="0" vspace="0" hspace="0" allowtransparency="true" scrolling="no" allow="attribution-reporting; run-ad-auction" src="https://googleads.g.doubleclick.net/pagead/html/r20241120/r20190131/zrt_lookup_fy2021.html#RS-0-&amp;adk=1812271808&amp;client=ca-pub-1564170154250560&amp;fa=8&amp;ifi=4&amp;uci=a!4" data-google-container-id="a!4" tabindex="0" title="Advertisement" aria-label="Advertisement" data-google-query-id="CJ_09LO-8IkDFRlcHgIdS0wFbw" data-load-complete="true"></iframe>
  (Session info: chrome=131.0.6778.86)
Stacktrace:
        GetHandleVerifier [0x00007FF7D0FF6CB5+28821]
        (No symbol) [0x00007FF7D0F63840]
        (No symbol) [0x00007FF7D0E0578A]
        (No symbol) [0x00007FF7D0E60E8E]
        (No symbol) [0x00007FF7D0E5E92C]
        (No symbol) [0x00007FF7D0E5BAF6]
        (No symbol) [0x00007FF7D0E5AA51]
        (No symbol) [0x00007FF7D0E4CBA0]
        (No symbol) [0x00007FF7D0E7F2FA]
        (No symbol) [0x00007FF7D0E4C3F6]
        (No symbol) [0x00007FF7D0E7F510]
        (No symbol) [0x00007FF7D0E9F412]
        (No symbol) [0x00007FF7D0E7F0A3]
        (No symbol) [0x00007FF7D0E4A778]
        (No symbol) [0x00007FF7D0E4B8E1]
        GetHandleVerifier [0x00007FF7D132FCAD+3408013]
        GetHandleVerifier [0x00007FF7D134741F+3504127]
        GetHandleVerifier [0x00007FF7D133B5FD+3455453]
        GetHandleVerifier [0x00007FF7D10BBDBB+835995]
        (No symbol) [0x00007FF7D0F6EB5F]
        (No symbol) [0x00007FF7D0F6A814]
        (No symbol) [0x00007FF7D0F6A9AD]
        (No symbol) [0x00007FF7D0F5A199]
        BaseThreadInitThunk [0x00007FFE74307374+20]
        RtlUserThreadStart [0x00007FFE7595CC91+33]
  • Вопрос задан
  • 62 просмотра
Подписаться 1 Простой Комментировать
Пригласить эксперта
Ответы на вопрос 1
Lord_of_Rings
@Lord_of_Rings
Дунадан - северный странник. Злой, но очень добрый
spoiler

import time

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver import Chrome, ChromeOptions
from selenium.common.exceptions import NoSuchElementException, StaleElementReferenceException


driver = Chrome()
url = 'https://sc2arcade.com/map-list'
driver.get(url)
maps_names = driver.find_elements(By.CLASS_NAME, 'title')
options = ChromeOptions()
options.add_argument("--disable-notifications")


required_letters = 'qwertyuiopasdfghjklzxcvbnm'


class MapMaker:
    def __init__(self, username, social_media_link, link_to_profile):
        self.username = username
        self.social_media_link = social_media_link
        self.link_to_profile = link_to_profile

    def __eq__(self, other):
        if isinstance(other, MapMaker):
            return self.value == other.value
        return False

    def __hash__(self):
        return hash(self.value)


mapmakers = set()


for map_name in maps_names:
    for required_letter in required_letters:
        for letter in map_name.text:
            if letter == required_letter:
                driver.execute_script("arguments[0].click();", map_name)
                map_name.click()
                try:
                    author = driver.find_element(By.CLASS_NAME, 'v-avatar v-list-item__avatar rounded-0 v-avatar--tile').text
                    link_on_profile = driver.find_element(By.CLASS_NAME, 'player-link').text
                    social_media_link = driver.find_element(By.CLASS_NAME, 'v-btn__content').text

                    mapmaker = MapMaker(author, link_on_profile, social_media_link)
                    mapmakers.add(mapmaker)
                    
                    driver.back()
                    driver.refresh()
                except NoSuchElementException:
                    pass


print(mapmakers)
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы