【问题标题】:Navigation error in Selenium: Link is not clickable at point (...). Other element would receive the click [duplicate]Selenium 中的导航错误:链接在点 (...) 处不可点击。其他元素将收到点击 [重复]
【发布时间】:2020-12-26 03:06:46
【问题描述】:

我想让 Selenium 浏览 this page 导航栏的项目,然后检索其内容并将它们传递给 beatifulsoup。

我的代码在第一页上运行良好,之后出现以下错误:

ElementClickInterceptedException: Message: element click intercepted: Element <a href="https://www.rollingstone.com/music/music-lists/500-greatest-songs-of-all-time-151127/smokey-robinson-and-the-miracles-shop-around-71184" style="color: rgb(211, 37, 49); padding: 4px 8px;">...</a> is not clickable at point (77, 73). Other element would receive the click: <div class="fc-dialog-overlay"></div>

以前的答案没有帮助。 这是我的代码。我真的很感激任何帮助。

webdriver.ChromeOptions()
options.add_argument('--ignore-certificate-errors')
options.add_argument('--incognito')
options.add_argument('--headless')
driver = webdriver.Chrome(options=options)

target_page = 'https://www.rollingstone.com/music/music-lists/500-greatest-songs-of-all-time-151127/'

driver.get(target_page)
header = driver.find_element_by_id('pmc-gallery-list-nav-bar-render')
items = header.find_elements_by_tag_name('a')

songs = []

for item in items:    
    driver.maximize_window()
    time.sleep(5)
    item.click()
    page_source = driver.page_source
    soup = BeautifulSoup(page_source)
    song_all = soup.find_all('h2', {'class':'c-gallery-vertical-album__title'})
    for song in song_all:
        songs.append(strip_extra_chars(song.get_text()))

driver.quit()

【问题讨论】:

  • 这意味着另一个元素正在接收点击使用 driver.executescript() 来定位并点击该元素。

标签: selenium web-scraping selenium-chromedriver


【解决方案1】:

让我们评论options.add_argument('--headless'),看看程序是如何运行的。 您需要确定哪个元素与您的链接重叠。 例如,我尝试运行您的代码并出现此对话框:

在这种情况下,要禁用通知,您可以添加:

prefs = {"profile.default_content_setting_values.notifications": 2}
options.add_experimental_option("prefs", prefs)

但此对话框与 .fc-dialog-overlay 定位器不匹配,因此您的问题可能与另一个元素有关。你需要找到它。

另一种解决方法,可以使用js点击driver.execute_script()

【讨论】:

猜你喜欢
  • 2023-03-19
  • 2019-02-20
  • 2021-12-31
  • 2016-06-08
  • 1970-01-01
  • 2017-04-16
  • 2018-03-16
  • 2017-11-27
相关资源
最近更新 更多