python-3.x - Python中的 "Other element would receive the click"错误

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

我试图单击这样的链接:

<div class="loading" style="display:none;">
<p class="btn blue"><span>さらに表示</span></p>
<a href="javascript:void(0);" onclick="get_more();"></a>
</div>

我使用了这段代码:
element = WebDriverWait(driver, 30).until(lambda x: x.find_element_by_css_selector(".btn.blue"))  # @UnusedVariable
element.click()

我收到这样的错误,该怎么解决?
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <p class="btn blue">...</p> is not clickable at point (391, 577). Other element would receive the click: <a href="javascript:void(0);" onclick="get_more();"></a>
(Session info: headless chrome=69.0.3497.100)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 6.1.7601 SP1 x86_64)

最佳答案

您尝试单击的元素已被其他元素覆盖,以便其他元素获得点击而不是实际元素。
实际元素可能没有被点击的可能性如下:

  • 案例1 。可以说,如果它是一个加载器,而该加载器是在元素获得加载并在一段时间后变得不可见的话。
    解决方案:在这里,您必须等到加载程序不可见之后,然后才必须单击实际元素
      from selenium.webdriver.support import expected_conditions as EC
      wait = WebDriverWait(driver, 10)
      element = wait.until(EC.invisibility_of_element_located((By.ID, 'loader_element_id')))
      element_button = wait.until(EC.element_to_be_clickable((By.ID, 'your_button_id')))
      element_button.click()
    
  • 案例2 。实际元素在浏览器维度中不可见,并被某些叠加元素覆盖。
    解决方案:在这里,您需要滚动到所需的元素,然后必须执行单击
      from selenium.webdriver.common.action_chains import ActionChains
    
      element = driver.find_element_by_id("your_element_id")
    
      actions = ActionChains(driver)
      actions.move_to_element(element).perform()
    
    或使用可以使用execute_script像:
      driver.execute_script("arguments[0].scrollIntoView();", element)
    
    或使用JavaScript执行点击。
      driver.execute_script("arguments[0].click();", element) 
    

  • 注意:如果需要,请根据Python语法进行必要的更正。

    关于python-3.x - Python中的 "Other element would receive the click"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52400233/

    相关文章:

    c# - Internet Explorer 保护模式设置和缩放级别

    java - Webdriver 确实存在时没有这样的元素,我已经等待了足够长的时间

    java - 我如何从下拉菜单中选择元素

    javascript - 断言selenium webdriver Node js

    python-3.x - 在线程中使用 psycopg2 游标的正确方法是什么?

    python - Python纽约时报网络抓取错误(“bytes to string”)

    python - 如何永久编辑(删除)sys.path?

    java - 使用 Selenium Webdriver 获取网页中的所有非隐藏链接并单击

    java - 如何断言包含以下内容的 if 语句

    python - 我将如何解析结果并将其插入变量?