【问题标题】:Selenium: element is not clickable because an other element obscures itSelenium:元素不可点击,因为其他元素遮住了它
【发布时间】:2021-05-29 20:51:12
【问题描述】:

我一直在搜索该网站,但似乎找不到适合我的修复程序。我正在尝试单击应该加载更多评论的按钮。

driver.get("https://www.mediamarkt.nl/nl/product/_philips-essential-airfryer-xl-hd9260-90-1653991.html")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".bv-content-btn-pages-load-more"))).click()

是我正在使用的代码。这会导致错误:

selenium.common.exceptions.ElementClickInterceptedException: Message: Element <button class="bv-content-btn bv-content-btn-pages bv-content-btn-pages-load-more bv-focusable" type="button"> is not clickable at point (674,670) because another element <div class="gdpr-cookie-layer gdpr-cookie-layer--show"> obscures it

我尝试获取元素然后单击它:

element = driver.find_element_by_class_name('bv-content-btn-pages-load-more')
driver.execute_script("arguments[0].click();", element)

我也尝试过使用动作链:

element = driver.find_element_by_class_name('bv-content-btn-pages-load-more')
ActionChains(driver).move_to_element(element).click().perform()

这里的实际问题是什么,我该如何解决?

【问题讨论】:

    标签: python python-3.x selenium selenium-webdriver


    【解决方案1】:
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, '[class="gdpr-cookie-layer__btn gdpr-cookie-layer__btn--submit gdpr-cookie-layer__btn--submit--all"]'))).click()
    
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
        (By.CSS_SELECTOR, ".bv-content-btn-pages-load-more"))).click()
    

    您必须先关闭接受 cookie 对话框,否则 selenium 无法单击加载更多元素,因为 accept_cookie 屏幕处于前台

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-07-05
      • 2020-09-24
      • 1970-01-01
      • 1970-01-01
      • 2018-08-21
      • 2018-12-19
      • 1970-01-01
      相关资源
      最近更新 更多